Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple If Statements

Status
Not open for further replies.

MisterMan

Technical User
Jun 4, 2002
87
US
Hi all,
I freely admit I am a nitwit, so any help would be appriciated since I know next to nothing about VBA coding.

What I am trying to do is have a form with a combo box (Got this much done) with several selections, for the sake of argument let us label them 1-4. Now, what I want to have happen is for the user of said form to be able to make a 1-4 selection, then click on a button named "Go". Once this is done, I was hoping (praying, making small sacrifices) that it would be possible to have a Query run on the basis of which number was chosen (For example, if someone chose the number "1" and then hit go, it would run Query 1).
I made an attempt at this, but my VBA skills are so limited that I didn't even get passed the fieldname that would be set equal as (For example if Combo1 = "1" then etc). I kept getting an error message when trying to run the code that "Statement invalid outside type block".
I hate asking for help, and I'm going to keep plugging away... but if anyone has any suggestions, I would be greatly appriciative.
Thank you
Josh
 
HI

It seems firstly you need to identify the values in your combo box, as these are the values you will be interrogating

Next, in the cmdGo_Click routine you could run a Select Case statement which will act upon your Combo Box value.

So, lets assume you are displaying the following values: 1, 2, 3 & 4

Next you can have the following Select Case statement behind the cmdGo button:

Code:
Select Case Me!ComboBox
   Case 1
      'Run query 1
   Case 2
      'Run Query 2
   Case 3
      'Run Query 3
   Case 4
      'Run query 4
End Select

This will in effect force the specific query to run, based on the value in the Combo Box. However, you will have to be specific on your data types. If the value stored is integer, then the code above will work, but if the value is a string, then you will need:

Code:
Select Case Me!ComboBox
   Case "1"
      'Run query 1
   Case "2"
      'Run Query 2
   Case "3"
      'Run Query 3
   Case "4"
      'Run query 4
End Select

Hope this helps!

birklea birklea ~©¿©~ <><
I know what I know...don't presume that I know what I don't! Smithism!!!
 
I apologize for being a moron but...
&quot;identify the values in your combo box&quot;

How does one go about that?
Thanks again!
 
The values are what you are displaying for the user. If he drops down the list, he is presented with something that is selectable, be it numbers (as in our example) or names, countries, dates...whatever you want to display. This is important, as this is what the &quot;Select Case&quot; statement will be working against.

So, if you are using Names in your Combo, the Select Case may look like this:
Code:
Select Case Me!ComboBox
   Case &quot;Smith&quot;
   Case &quot;Jones&quot;
End Select

Or you may be working agianst countries:
Code:
Select Case Me!ComboBox
   Case &quot;England&quot;
   Case &quot;Wales&quot;
End Select

That's all I meant by &quot;Identify the values&quot;. As long as you have the selecte value in your Select Case statement...then your queries will be selected.

Have I confused you now?

birklea
birklea ~©¿©~ <><
I know what I know...don't presume that I know what I don't! Smithism!!!
 
Oh thank you Birklea... You have helped me in a big way. I had to monkey with it a bit (Mostly cause I think I explained wrong), but it works like a charm now. Thank you again!
Josh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top