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

Run time error '3075': Syntax error (missing operator) in query expression

P: 4
hello,

I'm trying to get my list box database to open up another form that contains more information on the selected record. I can get it to open the form just fine, but it always opens o the first record, rather than the one I have selected.

My error message is: Run-time error '3075': Syntax error (mising operator) in query expression 'Serial Number = 7632-562'.

All my records in the database are made up numbers and letters, as I am just testing it out now before using real entries.

My code is:

Expand|Select|Wrap|Line Numbers
  1. Private Sub SearchList_DblClick(Cancel As Integer)
  2.  
  3.     DoCmd.OpenForm "frmInfo", acNormal, , "Serial Number = " & Me![SearchList].Value
  4.  
  5. End Sub
the listbox is called Search List, and the form i want to open is called frmInfo.

Thanks to anyone with advice!
2 Weeks Ago #1

✓ answered by twinnyfo

Square braces around your field name.
Expand|Select|Wrap|Line Numbers
  1. Private Sub SearchList_DblClick(Cancel As Integer)
  2.  
  3.     DoCmd.OpenForm "frmInfo", _
  4.                    acNormal, , _
  5.                    "[Serial Number] = '" & Me.SearchList & "'"
  6.  
  7. End Sub
You had a space in your Field Name, which you should try to avoid in the future, to avoid such errors.

Hope this hepps.

Share this Question
Share on Google+
8 Replies


100+
P: 144
If it was me, I would put in the query of the form under the serial column:

Like[Enter Serial No.]

And have your code just open the form.
2 Weeks Ago #2

P: 4
@DJRhino1175
I have a textbox up at the top that is used for searching through the databse by serial number, and the results are displayed in the listbox, so I though the best idea was to be able to click on one of the records in the listbox and just have that one come up.
2 Weeks Ago #3

twinnyfo
Expert Mod 2.5K+
P: 3,184
It appears the issue is that you are searching for a record that has a text serial number, but using the syntax for a numeric value. Just because a "Serial Number" looks like numbers, it is not necessarily numeric (notice that there is a dash in your Serial Number).

Try this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub SearchList_DblClick(Cancel As Integer)
  2.  
  3.     DoCmd.OpenForm "frmInfo", _
  4.                    acNormal, , _
  5.                    "Serial Number = '" & Me.SearchList & "'"
  6.  
  7. End Sub
Also note, there is no need to refer to the "value" of the control, as the Value is the default reference.

Hope this hepps!
2 Weeks Ago #4

P: 4
@twinnyfo
Hey thanks for you response! I didn't think about it that way, good insight. I copied and pasted the code you gave me into access but i still got the same error, can you think of a reason why that would happen?
2 Weeks Ago #5

twinnyfo
Expert Mod 2.5K+
P: 3,184
Square braces around your field name.
Expand|Select|Wrap|Line Numbers
  1. Private Sub SearchList_DblClick(Cancel As Integer)
  2.  
  3.     DoCmd.OpenForm "frmInfo", _
  4.                    acNormal, , _
  5.                    "[Serial Number] = '" & Me.SearchList & "'"
  6.  
  7. End Sub
You had a space in your Field Name, which you should try to avoid in the future, to avoid such errors.

Hope this hepps.
2 Weeks Ago #6

P: 4
@twinnyfo
Works perfectly! thank you!
2 Weeks Ago #7

twinnyfo
Expert Mod 2.5K+
P: 3,184
Glad I could be of service. Let us know if you need any more hepp!
2 Weeks Ago #8

NeoPa
Expert Mod 15k+
P: 31,347
Twinny has already answered perfectly adequately but it may help to have a look at Quotes (') and Double-Quotes (") - Where and When to use them for a fuller understanding.
2 Weeks Ago #9

Post your reply

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