If Then Else

G

Guest

I am a newbie at VBA

I have a form with a list box and based on what is selected from the list
box, I want the second column (which is hidden) to determine whether other
fields on the form are visible. I tried the code below, but only get the
results of the Else statement, no matter what I choose from the list box.

Private Sub lstReports_AfterUpdate()
If Me.lstReports.Column(1) = "Date Product Fund" Then
Me.CA.Visible = False
Me.CallType.Visible = False
ElseIf Me.lstReports.Column(1) = "Date Product" Then
Me.CA.Visible = False
Me.CallType.Visible = False
Me.FundPolicy.Visible = False
Else
Me.BeginningDate.Visible = True
Me.EndDate.Visible = True
End If
End Sub

Thanks
 
G

Guest

Karen,

Is your listbox setup as a multi-select? If so, change it to "None". It
looks like you already realize that the Listbox columns are zero based, which
is a frequent problem.

Have you run the query that is the RowSource for your listbox to see what
the results are, to confirm that you actually have records that look like
"Date Product Fund" and "Date Product"?

Now that I look at it closer, I'm not exactly sure what you are trying to
do? Do you want BeginningDate and EndDate to be visible if column(1) = "Date
Product Fund" or "Date Product", if not you need to hide them in either of
these cases. I would think you need to refer to each of the 5 controls
mentioned in each of the sections of the If .. ElseIf .. Else .. EndIF clause.

HTH
Dale
 
G

Guest

That worked. However, I thought maybe instead of Visible, I would change it
to Enabled. This did not work. Is there additional code to be used when
using Enabled?
 
D

Dale Fye

Karen,

Should work equally well for enable as it does for visible. The only twist
is that you cannot disable a control that has the focus, so you won't be
able to disable the listbox.

Post your new code and I'll take a look.

Dale
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top