Connecting Tech Pros Worldwide Forums | Help | Site Map

How to do piece of VB code?

Jim
Guest
 
Posts: n/a
#1: Nov 13 '05
I have a form that has numerous fields on it, but one of them is called
"Sort Type" (dropdown) and another is called "Item Count" (number) I
want to show or hide the Item Count field based on the value selected
in Sort Type.

I was going to put an After Update even on Sort Type that looked
something like this:

If cboSortType = 120 Or 125 Or 130 Or 135 Or 140 Or 145 Or 150 Or
155 Or 160 Or 165 Or 170 Or 175 Or 180 Or 185 Or 245 Or 190 Or 195 Or
200 Or 205 Or 210 Or 215 Or 220 Or 225 Or 230 Or 235 Or 240 Then
Me!ItemCount.Visible = True
Else
Me!ItemCount.Visible = False
End If

Seems like it's not going to work correctly... is there just an easier
way? I seem to recall some sort of "IN" function...


Wayne Morgan
Guest
 
Posts: n/a
#2: Nov 13 '05

re: How to do piece of VB code?


Yes, I believe there is an easier way to do this. Using what you have, the
correct syntax would be

If cboSortType = 120 Or cboSortType = 125 Or cboSortType = 130 'etc

To shorten this there are a few options. Here are two that should help.

Select Case cboSortType
Case 120, 125, 130, 135, 140 'etc
Me!ItemCount.Visible = True
Case Else
Me!ItemCount.Visible = False
End Select

Or

If (cboSortType >=120 And cboSortType <= 240) And (cboSortType Mod 5 = 0)
Then

There is an In Clause that is used in queries (SQL).

--
Wayne Morgan
MS Access MVP


"Jim" <jlrehmann@gmail.com> wrote in message
news:1116440444.648174.112570@g14g2000cwa.googlegr oups.com...[color=blue]
>I have a form that has numerous fields on it, but one of them is called
> "Sort Type" (dropdown) and another is called "Item Count" (number) I
> want to show or hide the Item Count field based on the value selected
> in Sort Type.
>
> I was going to put an After Update even on Sort Type that looked
> something like this:
>
> If cboSortType = 120 Or 125 Or 130 Or 135 Or 140 Or 145 Or 150 Or
> 155 Or 160 Or 165 Or 170 Or 175 Or 180 Or 185 Or 245 Or 190 Or 195 Or
> 200 Or 205 Or 210 Or 215 Or 220 Or 225 Or 230 Or 235 Or 240 Then
> Me!ItemCount.Visible = True
> Else
> Me!ItemCount.Visible = False
> End If
>
> Seems like it's not going to work correctly... is there just an easier
> way? I seem to recall some sort of "IN" function...
>[/color]


Jim
Guest
 
Posts: n/a
#3: Nov 13 '05

re: How to do piece of VB code?


Thanks man... forgot all about Select Case statements. Works great!

Closed Thread