473,414 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 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 6470
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.