467,877 Members | 1,209 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,877 developers. It's quick & easy.

Syntax for using findrecord on two variables

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
  • viewed: 6072
Share:
2 Replies
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
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.

Similar topics

8 posts views Thread by Ken in Melbourne Australia | last post: by
699 posts views Thread by mike420 | last post: by
4 posts views Thread by Toonman | last post: by
15 posts views Thread by Tony Williams | last post: by
16 posts views Thread by danu | last post: by
1 post views Thread by Keith Wilby | last post: by
reply views Thread by Ben Lahoy | last post: by
reply views Thread by jack112 | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.