472,976 Members | 1,201 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,976 software developers and data experts.

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
2 6442
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ken in Melbourne Australia | last post by:
If I use the curly bracket syntax (referred to as the complex syntax) within a string, how do I get to call a function within it? The php manual says that the first (or previous) character for...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
4
by: Toonman | last post by:
I'm trying to use a couple of variables in a stored procedure. Things work fine when I hard code the data into the variables and also work fine when I use the variable in the WHERE clause and hard...
15
by: Tony Williams | last post by:
I have two forms, frma and frmb, both are for inputting new records and are based on a table, tblmonth, both have two controls, txtmonth and txtmonthlabela which are based on the fields in the...
16
by: danu | last post by:
I have a structure : typedef struct{ char magicNum; int width; int height; int maxGrey; int pixels; } ImageT;
2
by: tehgreatmg | last post by:
Ok what I have is a list of boxes on a form that are connected to fields in my database. There is an extra box I want to be able to put the record number in and it automatically load the data...
1
by: Keith Wilby | last post by:
When I run this line of code from a command button on a form DoCmd.FindRecord "Domestic FW System", acStart, , acDown, , acCurrent I get the error "A macro set to one of the current field's...
4
by: RAG2007 | last post by:
Hi Having some problems with docmd.findrecord, getting runtime error 2162, in an adp, sql server back end. On my main form, I have a continuous view subform giving a list of subrecords within...
0
by: Ben Lahoy | last post by:
Hi! My problem is basically in a search modal window, where the user is allowed to make a selection on which option to take. After selecting an option and then giving the data to search, the...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.