.value in

A

alex

Hello,

I'm looking to change this code:

..value = "example1"

to .value in ("example1", "example2").

The latter doesn't work of course.

I could do this .value = "example1" or "example2", but if the list is
long it's going to be tedious.

any thougts?
alex
 
D

Douglas J. Steele

Where are you trying to do this?

(FWIW, you can't do .value = "example1" or "example2". It would have to be
..value = "example1" or .value = "example2")
 
A

alex

Where are you trying to do this?

(FWIW, you can't do .value = "example1" or "example2". It would have tobe
.value = "example1" or .value = "example2")

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no e-mails, please!)












- Show quoted text -

Doug,

I'm trying to hide a textbox on a subform based on the value of
listbox on the main form.

I have this code already (and it works fine):
if .value = "example1" then

What I wanted to do was hide the textbox based on 5 values in the list
box. I was hoping that [if .value in ()] would work but it does not.

As you mentioned above, I could do .value = "" or .value = "". But, I
thought there must be a way to just list out the values.

Something like:
if .value = (list of values) then

alex
 
D

Douglas J. Steele

One approach is

If InStr(";" & .value & ";", ";example1;example2;example3;") > 0 Then
' value is one of the values wanted
Else
' value is not one of the values wanted
End If
--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Doug,

I'm trying to hide a textbox on a subform based on the value of
listbox on the main form.

I have this code already (and it works fine):
if .value = "example1" then

What I wanted to do was hide the textbox based on 5 values in the list
box. I was hoping that [if .value in ()] would work but it does not.

As you mentioned above, I could do .value = "" or .value = "". But, I
thought there must be a way to just list out the values.

Something like:
if .value = (list of values) then

alex
 
J

John Spencer

You could use a Select Case Statement

Select Case .Value
Case "A","B", "C", "D", "E"
'do something
End Select

Or you could use this if the values are unique

If Instr(1,"ABCDE",.Value)>0 THEN
'Do something
End If

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================

Where are you trying to do this?

(FWIW, you can't do .value = "example1" or "example2". It would have to be
.value = "example1" or .value = "example2")

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no e-mails, please!)





- Show quoted text -

Doug,

I'm trying to hide a textbox on a subform based on the value of
listbox on the main form.

I have this code already (and it works fine):
if .value = "example1" then

What I wanted to do was hide the textbox based on 5 values in the list
box. I was hoping that [if .value in ()] would work but it does not.

As you mentioned above, I could do .value = "" or .value = "". But, I
thought there must be a way to just list out the values.

Something like:
if .value = (list of values) then

alex
 
A

alex

You could use a Select Case Statement

Select Case .Value
  Case "A","B", "C", "D", "E"
    'do something
End Select

Or you could use this if the values are unique

If Instr(1,"ABCDE",.Value)>0 THEN
   'Do something
End If

'====================================================
  John Spencer
  Access MVP 2002-2005, 2007-2008
  The Hilltop Institute
  University of Maryland Baltimore County
'====================================================


I'm trying to hide a textbox on a subform based on the value of
listbox on the main form.
I have this code already (and it works fine):
if .value = "example1" then
What I wanted to do was hide the textbox based on 5 values in the list
box.  I was hoping that [if .value in ()] would work but it does not.
As you mentioned above, I could do .value = "" or .value = "".  But, I
thought there must be a way to just list out the values.
Something like:
if .value = (list of values) then
alex- Hide quoted text -

- Show quoted text -

Thanks guys for your help. I'm going to try the Instr().
alex
 
J

Jeff Boyce

Alex

It sounds like you have a listbox with items, a specific set of 5 of which
would be cause to change your textbox visibility.

What happens when the list of 'trigger' items changes (grows, shrinks, ...)?
Are you going to go back through your code, macros, queries, etc. and be
able to find all the places that need to be changed?

If this is unlikely to happen (a change), your approach is probably
sufficient.

If this is either likely to happen or "could NEVER happen", you might want
to look into an alternate approach, one that uses a table to hold 'trigger'
values. Then you can check to see if what was selected in the listbox is in
the table of triggers...

Good luck!

Regards

Jeff Boyce
Microsoft Office/Access MVP

Where are you trying to do this?

(FWIW, you can't do .value = "example1" or "example2". It would have to be
.value = "example1" or .value = "example2")

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no e-mails, please!)












- Show quoted text -

Doug,

I'm trying to hide a textbox on a subform based on the value of
listbox on the main form.

I have this code already (and it works fine):
if .value = "example1" then

What I wanted to do was hide the textbox based on 5 values in the list
box. I was hoping that [if .value in ()] would work but it does not.

As you mentioned above, I could do .value = "" or .value = "". But, I
thought there must be a way to just list out the values.

Something like:
if .value = (list of values) then

alex
 
A

alex

Alex

It sounds like you have a listbox with items, a specific set of 5 of which
would be cause to change your textbox visibility.

What happens when the list of 'trigger' items changes (grows, shrinks, ....)?
Are you going to go back through your code, macros, queries, etc. and be
able to find all the places that need to be changed?

If this is unlikely to happen (a change), your approach is probably
sufficient.

If this is either likely to happen or "could NEVER happen", you might want
to look into an alternate approach, one that uses a table to hold 'trigger'
values.  Then you can check to see if what was selected in the listbox is in
the table of triggers...

Good luck!

Regards

Jeff Boyce
Microsoft Office/Access MVP


Where are you trying to do this?
(FWIW, you can't do .value = "example1" or "example2". It would have to be
.value = "example1" or .value = "example2")
- Show quoted text -

Doug,

I'm trying to hide a textbox on a subform based on the value of
listbox on the main form.

I have this code already (and it works fine):
if .value = "example1" then

What I wanted to do was hide the textbox based on 5 values in the list
box.  I was hoping that [if .value in ()] would work but it does not.

As you mentioned above, I could do .value = "" or .value = "".  But, I
thought there must be a way to just list out the values.

Something like:
if .value = (list of values) then

alex- Hide quoted text -

- Show quoted text -

Thanks Jeff!
 

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