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

Syntax for using findrecord on two variables

P: n/a
Hello, I was wondering if anyone could help me with this. I've done
some searching and found it's a common problem:

I'm trying to search a recordset that has two key fields: One is a long
and the other a string

strCriteria = "ID=" & Me.cmdIDNumber & " AND Ctgry='" &_
Me.cmdCategory & "'"

With Me.RecordsetClone
..FindFirst strCriteria
End With

Unfortunately, when I run the operation, I get an "Invalid syntax
(Missing Operator)" function. I've tried time and time again with
different methods. Any help!

Thank you very much in advance.

Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Your syntax is correct if:
- ID is a Number type field,
- cmdIdNumber is a combo(?), and the bound column is a number,
- Ctgry is a Text type field,
- The bound column of cmdCategory is the correct text,
- There is no apostrophy in the text in cmdCategory.

You could try adding brackets and using double quotes, e.g.:
strCriteria = "([ID] = " & Me.cmdIDNumber & ") AND (Ctgry = """ & _
Me.cmdCategory & """)"

If it still doesn't work, get each half to work on its own.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<to*********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hello, I was wondering if anyone could help me with this. I've done
some searching and found it's a common problem:

I'm trying to search a recordset that has two key fields: One is a long
and the other a string

strCriteria = "ID=" & Me.cmdIDNumber & " AND Ctgry='" &_
Me.cmdCategory & "'"

With Me.RecordsetClone
.FindFirst strCriteria
End With

Unfortunately, when I run the operation, I get an "Invalid syntax
(Missing Operator)" function. I've tried time and time again with
different methods. Any help!

Thank you very much in advance.

Nov 13 '05 #2

P: n/a
Allen,

You are a life saver! It turned out to be the brackets idea that
worked. Essentially, I inherited field names that included a space and
not an underscore. What I called "Ctgry" above was actually "Curr
Category." Once I changed the search string to read [Curr Category],
the problem was easily solved with your help!
Thanks for taking out the time and covering so much!

Tom

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.