By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,506 Members | 2,252 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,506 IT Pros & Developers. It's quick & easy.

How do I pull up a form based on combo box selection?

P: 43
Hey everyone,

I am fairly new to Access and I am having trouble getting something working on my database, hopefully someone can help me out!

I have a combo box called cboTest based on a query called Trailer_Detail. TRLR_NBR is the title of the column in the query. It lists a group of about 200 trailer numbers. When I select a trailer number and click a button called Test, I want it to pull up a form called Trailer_Detail1 and display the trailer number and the remaining information on my Trailer_Detail query.

One code I have tried is:

Dim strWhere As String
strWhere = "[TRLR_NBR] = " & Me.[cboTest]
DoCmd.OpenForm "Trailer_Detail1", acViewForm, , strWhere, acWindowNormal

Everytime I try this code and some other codes I have seen online, the form comes up empty. Please help if you can!

-Ben
Jan 9 '12 #1

✓ answered by Seth Schrock

Not if you make sure that the Bound To Column property of the combo box stays on the TRLR_NBR column. So if you add the column TRLR_DESCRIPTION (I'm making up the name), find out which column number TRLR_NBR is in (starting from the left) and put its column number into that property. Make sense?

PS Don't forget to choose best answer.

Share this Question
Share on Google+
8 Replies


P: 43
I did notice that when I double clicked the button it worked for some reason, although I'm positive that it is assigned under Test_Click. Any ideas?
Jan 9 '12 #2

Expert Mod 2.5K+
P: 2,545
The example you give should work well IF your trailer number is defined as a number. It will not work at all if your trailer number is not defined as numeric but is instead a text field.

If this is the case, change the line setting your filter string to

Expand|Select|Wrap|Line Numbers
  1. strWhere = "[TRLR_NBR] = '" & Me.[cboTest] & "'"
-Stewart
Jan 9 '12 #3

Seth Schrock
Expert 2.5K+
P: 2,931
Try using the DoCmd.OpenForm command without the variable strWhere. So it would look like the following.

Expand|Select|Wrap|Line Numbers
  1. Docmd.OpenForm "Trailer_Detail1", acViewForm, ,"[TRLR_NBR]=" & cboTest
You don't need the acWindowNormal at the end as that is the default. You probably don't need the acViewForm in the middle either, unless you have the default set as something else, like Data Sheet.
Jan 9 '12 #4

Expert Mod 2.5K+
P: 2,545
In your second post you mention the double-click event. This is beside the point I think - unless what you wrote in post # 1 is incorrect, where you said

Everytime I try this code and some other codes I have seen online, the form comes up empty
The form will not open at all on-click if you have put the code in the wrong event. Remember that performing a double click will first fire the on-click event if it exists.

-Stewart
Jan 9 '12 #5

P: 43
Wow, thanks so much Seth, it worked! I almost put my head through the wall I was getting so frustrated
Jan 9 '12 #6

P: 43
Thank you as well Stewart, this was a big help!
Jan 9 '12 #7

P: 43
Now what if I had two columns, the TRLR_NBR column and another column in the combo box? How would this change the code?
Jan 9 '12 #8

Seth Schrock
Expert 2.5K+
P: 2,931
Not if you make sure that the Bound To Column property of the combo box stays on the TRLR_NBR column. So if you add the column TRLR_DESCRIPTION (I'm making up the name), find out which column number TRLR_NBR is in (starting from the left) and put its column number into that property. Make sense?

PS Don't forget to choose best answer.
Jan 9 '12 #9

Post your reply

Sign in to post your reply or Sign up for a free account.