Re: Set The Visibility of A Control Based Off A Combo Box Option

Tech-Archive recommends: Speed Up your PC by fixing your registry



So theoretically this code should work

Private Sub Heard_About_Us_AfterUpdate()
If Me.Heard_About_Us = "Other" Or Me.Heard_About_Us = "POSTED ELSEWHERE" Or
Me.Heard_About_Us = "WORD OF MOUTH" Then
Me.Heard_About_Us_Explain.Visible = True
Else
Heard_About_Us_Explain.Visible = False
End If
End Sub

Because when I try to run this code I get all sorts of Compiler Errors

* COMPILER ERROR : EXPECTED EXPRESSION

And the following code is highlighted in Red
If Me.Heard_About_Us= "Other" Or Me.Heard_About_Us = "POSTED ELSEWHERE" Or
Me.Heard_About_Us = "WORD OF MOUTH" Then

"Rob Oldfield" wrote:

>
> Lose the me. before the word Private (Klatuu - think you missed your typo)
> and the speech mark after the word Then.
>
>
> "Set The Visibility of A Control"
> <SetTheVisibilityofAControl@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:E37B30D5-EEA1-4D8A-804B-5B07AB57B748@xxxxxxxxxxxxxxxx
> > I just keep getting Syntax error Codes. For the first two lines of the
> Code
> >
> > Me.Private Sub Heard_About_Us_AfterUpdate()
> > If Me.Heard_About_Us = "Other" Or Me.Heard_About_Us = "POSTED ELSEWHERE"
> Or
> > Me.Heard_About_Us = "WORD OF MOUTH" Then"
> >
> > "Klatuu" wrote:
> >
> > > Not a problem at all.
> > > So here is how you can debug your code to see what you are actuaill
> getting.
> > > Open your VB Editor so the code you want to test is displayed.
> > > Place the cursor where you want the code to stop. In this case, it will
> be
> > > the first line of executable code. (not tags or dims, but a line of code
> that
> > > does something)
> > > Press F9. You will see that line of code change color.
> > > Open the form in form view and do whatever action is necessary to make
> the
> > > code execute. In this case, make a selection in the combo box.
> > > Your code should then appear. If it does not, select the VB Editor from
> the
> > > task bar.
> > > You should then see the line of code you highlighted earlier is now
> yellow.
> > > It is about to execute this code.
> > > Press F8
> > > The highlighted code will execute and the next line of code to execute
> will
> > > be highlighted in yellow.
> > > At any time the code is stopped, you can position your cursor over a
> > > variable and it will display a box showing the current value. You can
> also
> > > see the value of any object containing data or the setting of a property
> by
> > > referencing it in the immediate window. For example:
> > >
> > > ?forms!MyFormName!Heard_About_Us
> > > will display whatever the current selection is in the combo box.
> > > ?forms!MyFormName!Heard_About_Us.RowSource
> > > will display the the string of the current value of the rowsource
> property.
> > >
> > > Step through your code to be sure it is behaving as you expect.
> > > Check you variable values and property settings to ensure they contain
> the
> > > values you expect.
> > >
> > > "Set The Visibility of A Control" wrote:
> > >
> > > > I cant say as I do ... Like I said Relitively new .. I know this must
> be kind
> > > > of frustrating for you to answer the same questions over and over
> again.
> > > > Thank you so much
> > > >
> > > > "Klatuu" wrote:
> > > >
> > > > > It is not before the sub name. The sub name is Sub
> > > > > Heard_About_Us__AfterUpdate(). It is to qualify the control name.
> Although
> > > > > not always a necessity, it is a good idea that will avoid any
> ambiguity in
> > > > > naming. Me is a shorthand qualifier that references the current
> form.
> > > > > Rather than using:
> > > > > Forms!MyFormName!MyControlName
> > > > > You can use
> > > > > Me.MyControlName
> > > > > Or
> > > > > Me!MyControlName
> > > > >
> > > > > Just plain MyControlName will usually work, but it is better to
> qualify your
> > > > > object references.
> > > > >
> > > > > As to it not working, It looks okay, but you never know. Do you
> know how to
> > > > > trace code in Debug mode?
> > > > >
> > > > > "Set The Visibility of A Control" wrote:
> > > > >
> > > > > > For Some Reason this Code Dosent Seem to Work. What is the Me.
> Thing before
> > > > > > the Sub name ?
> > > > > >
> > > > > > "Klatuu" wrote:
> > > > > >
> > > > > > > Me.Private Sub Heard_About_Us__AfterUpdate()
> > > > > > > If Me.Heard_About_Us = "Other" Or Me.Heard_About_Us = "POSTED
> ELSEWHERE" Or
> > > > > > > Me.Heard_About_Us = "WORD OF MOUTH" Then
> > > > > > > Me.Heard_About_Us_Explain.Visible = True
> > > > > > > Else
> > > > > > > Heard_About_Us_Explain.Visible = False
> > > > > > > End If
> > > > > > > End Sub
> > > > > > >
> > > > > > >
> > > > > > > "Set The Visibility of A Control" wrote:
> > > > > > >
> > > > > > > > Did anyone have a code snippet to make this happen. I have
> tried but I am new
> > > > > > > > to VB and am confused by some of its syntax. My code snippet
> that I have
> > > > > > > > tried Is as follows.
> > > > > > > >
> > > > > > > > Private Sub Heard_About_Us__AfterUpdate()
> > > > > > > > If Heard_About_Us = "Other" Or "POSTED ELSEWHERE" Or "WORD OF
> MOUTH" Then
> > > > > > > > Heard_About_Us_Explain.IsVisible = True
> > > > > > > > Else
> > > > > > > > Heard_About_Us_Explain.IsVisible = False
> > > > > > > > End If
> > > > > > > > End Sub
> > > > > > > >
> > > > > > > > The Combo Box Is Named Heard_About_Us and has 6 options in it.
> > > > > > > > The Control I want to Make Visible Based On the Combo Box
> Criteria is Called
> > > > > > > > Heard_About_Us_Explain .
> > > > > > > >
> > > > > > > > Can U help Me Or anyone Else for that matter ?
>
>
>
.



Relevant Pages

  • Re: Printing the Form
    ... Private Sub Command1_Click ... The problem with parts of your drawing failing to print is probably because your PictureBoxes are not Autoredraw, but the PrintForm method also has various other problems printing the contents or background of containers, especially if they are themselves contained in other containers. ... There are many ways of doing this, depending on whether the Form you wish to print is fully visible on the display at the time you want to print it, or whether you wish to print a Form that is not fully visible on the display, and in some cases depending on whether you wish the code to work on versions of Windows prioer to XP. ...
    (microsoft.public.vb.general.discussion)
  • Re: TKinter, buttonwidget response problem(1) and all btns the same size(2)!
    ... That code tells python to execute the Display function and assign the ... function's return value to the variable command. ... there is data that you want code inside another class method to be ...
    (comp.lang.python)
  • RE: From Help
    ... To see how my approach works, create a new document called Test1. ... This will create a user form named UserForm1. ... Private Sub CommandButton1_Click ... This should display the code for the Document_New ...
    (microsoft.public.word.vba.general)
  • Re: Combo Box text display problem based on AfterUpdate...
    ... Private Sub Form_Current ... The cboStore and cboEmployee display fine. ... "Ken Snell " wrote: ... <MS ACCESS MVP> ...
    (microsoft.public.access.forms)
  • Re: Trouble displaying info from access db
    ... set Label Value ... not getting the Subject Code to display in the Label? ... Private Sub Form1_Load(ByVal sender As System.Object, ... Dim intRecordCount As Integer ...
    (microsoft.public.dotnet.languages.vb)