A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

VBA Code Help



 
 
Thread Tools Display Modes
  #1  
Old May 1st, 2008, 05:53 PM posted to microsoft.public.access.forms
[email protected]
external usenet poster
 
Posts: 24
Default VBA Code Help

Hello. Thanks for the help.

I have a form where I am using an if/then code to open a subform.

Example:

If Color = "Red" Then
Do this
ElseIf Color ="Blue" Then
Do This
ElseIf
'Any other......


I want to know if there is a way to make one of my ElseIf selections
have more than one option. Something like:

If Color = "Red" Then
Do this
ElseIf Color = "Blue" Then
Do This
ElseIf Color = "Orange" Or "Purple" Or "Yellow"
Do This

Thanks Again.
  #2  
Old May 1st, 2008, 06:19 PM posted to microsoft.public.access.forms
Roger Carlson
external usenet poster
 
Posts: 824
Default VBA Code Help

ElseIf Color = "Orange" Or Color = "Purple" Or Color = "Yellow" Then

Or you could also use a Case Statement

Select Case Color
Case "Red"
Debug.Print "Do This"
Case "Blue"
Debug.Print "Do That"
Case "Orange", "Purple", "Yellow"
Debug.Print "Do the other thing"
Case Else
Debug.Print "Do the last thing"
End Select

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/...UBED1=ACCESS-L

wrote in message
...
Hello. Thanks for the help.

I have a form where I am using an if/then code to open a subform.

Example:

If Color = "Red" Then
Do this
ElseIf Color ="Blue" Then
Do This
ElseIf
'Any other......


I want to know if there is a way to make one of my ElseIf selections
have more than one option. Something like:

If Color = "Red" Then
Do this
ElseIf Color = "Blue" Then
Do This
ElseIf Color = "Orange" Or "Purple" Or "Yellow"
Do This

Thanks Again.



  #3  
Old May 1st, 2008, 07:21 PM posted to microsoft.public.access.forms
B. Edwards
external usenet poster
 
Posts: 24
Default VBA Code Help

IF color = "Red" then
' do stuff
ELSEIF color = "Orange" OR color = "Purple" OR color = "Yellow"
' do other stuff
ELSE
' do default stuff
END IF

Personally, though I would probably:
1. use a CASE statement
or
2. create a lookup table that contains the color and the name of the subform
and then perform a lookup to retrieve the name of the form to open based on
the color.
or
3. use arrays in a similar fashion to #2
or
4. if the user is picking a color use a two column combo box that contains
the color in one column and the formname in a second hidden column

wrote in message
...
Hello. Thanks for the help.

I have a form where I am using an if/then code to open a subform.

Example:

If Color = "Red" Then
Do this
ElseIf Color ="Blue" Then
Do This
ElseIf
'Any other......


I want to know if there is a way to make one of my ElseIf selections
have more than one option. Something like:

If Color = "Red" Then
Do this
ElseIf Color = "Blue" Then
Do This
ElseIf Color = "Orange" Or "Purple" Or "Yellow"
Do This

Thanks Again.



  #4  
Old May 1st, 2008, 10:17 PM posted to microsoft.public.access.forms
[email protected]
external usenet poster
 
Posts: 24
Default VBA Code Help

Thank you both very much. Works like a charm.
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:07 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.