Unsolved
This post is more than 5 years old
2 Intern
•
131 Posts
0
7496
May 21st, 2008 19:00
Access question - Query from a form - criteria from Combo Box
Access 2003
I have very simple form with one ComboBox to select software titles. I just want to see every computer with a specific piece of software installed. If someone could explain why queries run from the form return nothing, I'd sure appreciate it.
Query is named "Software Search"
Form is named "Software Search"
Combox box is named "SoftwareList"
Criteria of the query is "Like [forms]![software search]![softwarelist]"
I can select from the list and run the query from a command button and get nothing, but I can run the query outside the form and type in a name, and it works fine. The following is the code for the On Click event of the button:
Private Sub Command2_Click()
On Error GoTo Err_Command2_Click
Dim stDocName As String
stDocName = "Software search"
DoCmd.OpenQuery stDocName, acNormal, acReadOnly
Exit_Command2_Click:
Exit Sub
Err_Command2_Click:
MsgBox Err.Description
Resume Exit_Command2_Click
End Sub


abach
1.7K Posts
0
May 21st, 2008 23:00
If you need the Like keyword the line of code would be
Like [Forms]![Software Search]![Softwarelist] & "*"
However I'm not sure you may need the Like keyword, so, if you don't need the wildcard (*), just list
[Forms]![Software Search]![Softwarelist]
Also, it isn't necessary to have the acNormal, as this is the default. So, your line of code would be
DoCmd.OpenQuery stDocName, , acReadOnly
A good piece of advice is not to use the same name for the query and form, as this could confuse Access. I recommend qrySoftwareSearch for the query and frmSoftwareSearch for the form (no spaces saves time when using objects in code)
Hope this helps...
ConesE
2 Intern
•
131 Posts
0
May 22nd, 2008 12:00
I appreciate your response. I'm obviously new to Access and have a lot to learn. I made my living for years writing Clipper apps, so I've got some idea how to design a database, but dang! This is different.
It turns out my answer was very simple. The bound column of the Combo Box was set to 1. I took that to be the column in the drop down, but noooo. I wanted the second column in the table. I changed it to 2 and it works.
I will definitely file your advice away for future reference. What I'm doing now is just quick, dirty apps for my own use, but I do want to learn and need to do a better job with my naming conventions.
My reasoning for using "Like" is that I'd ultimately like to allow the user to choose something like "Microsoft Office*" to get all versions of the software.
Thanks loads