473,396 Members | 1,998 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,396 software developers and data experts.

Using AND operator with FindFirst method

7
I'm using FindFirst method in Access VBA to find a particular record in a recordset. I have 2 search criteria each of which works just fine if used separately as an argument in FindFirst, but NOT in combination with one another. I tried various combinations of quotes, double quotes, brackets and paranthesis but in case of using 2 conditions I'm still receiving the error message saying "run-time error 13 - type mismatch". If I use just one of them then there are no error codes, so it looks like I simply can't remember the right syntax, i.e. there aren't, in fact, any data type mismatches.

This is the code that doesn't work:

Set rst = dbs.OpenRecordset("tblCustomer", dbOpenDynaset)
With rst
.FindFirst "[CustID] = ' " & rstOtherTBL!CustID & " ' " And _
"[Date] = #" & StartDate & "# "
'Other Statements
End With

However, these 2 pieces of code work just fine:

Set rst = dbs.OpenRecordset("tblCustomer", dbOpenDynaset)
With rst
.FindFirst "[CustID] = ' " & rstOtherTBL!CustID & " ' "
'Other Statements
End With

Set rst = dbs.OpenRecordset("tblCustomer", dbOpenDynaset)
With rst
.FindFirst "[Date] = #" & StartDate & "# "
'Other Statements
End With

Anybody knows how to resolve it?

Thanks a lot in advance!
Jun 4 '07 #1
7 19570
puppydogbuddy
1,923 Expert 1GB
I'm using FindFirst method in Access VBA to find a particular record in a recordset. I have 2 search criteria each of which works just fine if used separately as an argument in FindFirst, but NOT in combination with one another. I tried various combinations of quotes, double quotes, brackets and paranthesis but in case of using 2 conditions I'm still receiving the error message saying "run-time error 13 - type mismatch". If I use just one of them then there are no error codes, so it looks like I simply can't remember the right syntax, i.e. there aren't, in fact, any data type mismatches.

This is the code that doesn't work:

Set rst = dbs.OpenRecordset("tblCustomer", dbOpenDynaset)
With rst
.FindFirst "[CustID] = ' " & rstOtherTBL!CustID & " ' " And _
"[Date] = #" & StartDate & "# "
'Other Statements
End With

However, these 2 pieces of code work just fine:

Set rst = dbs.OpenRecordset("tblCustomer", dbOpenDynaset)
With rst
.FindFirst "[CustID] = ' " & rstOtherTBL!CustID & " ' "
'Other Statements
End With

Set rst = dbs.OpenRecordset("tblCustomer", dbOpenDynaset)
With rst
.FindFirst "[Date] = #" & StartDate & "# "
'Other Statements
End With

Anybody knows how to resolve it?

Thanks a lot in advance!
Try this:
Expand|Select|Wrap|Line Numbers
  1. .FindFirst "[CustID] = ' " & rstOtherTBL!CustID & " ' "  _
  2. & "And [Date] = #" & StartDate & "# "
  3.  
Jun 5 '07 #2
puppydogbuddy
1,923 Expert 1GB
Try this:
Expand|Select|Wrap|Line Numbers
  1. .FindFirst "[CustID] = ' " & rstOtherTBL!CustID & " ' "  _
  2. & "And [Date] = #" & StartDate & "# "
  3.  
oops! forgot a space before the And:
Expand|Select|Wrap|Line Numbers
  1. .FindFirst "[CustID] = ' " & rstOtherTBL!CustID & " ' "  _
  2. & " And [Date] = #" & StartDate & "# "
  3.  
Jun 5 '07 #3
waltvw
7
Thanks a lot, it now works!
Jun 5 '07 #4
puppydogbuddy
1,923 Expert 1GB
Thanks a lot, it now works!
You are most welcome. Glad I could help.
Jun 5 '07 #5
waltvw
7
It works but I just discovered that either Date or CustID is not taken into consideration in the evaluation, i.e. only one condition can actually be used in FindFirst as opposed to "Where" clause in SQL statement that can use multiple AND's & OR's. This is because my next statement, If .NoMatch evaluates to True even if there are records in the table that has a combination of CustID and Date which have been evaluated by .FindFirst statement. If that's the case, I'm still OK, 'cause before I got your response on how to fix the syntax in question I had created some logic in the loop to get around the issue.

Thanks again!
Jun 5 '07 #6
puppydogbuddy
1,923 Expert 1GB
It works but I just discovered that either Date or CustID is not taken into consideration in the evaluation, i.e. only one condition can actually be used in FindFirst as opposed to "Where" clause in SQL statement that can use multiple AND's & OR's. This is because my next statement, If .NoMatch evaluates to True even if there are records in the table that has a combination of CustID and Date which have been evaluated by .FindFirst statement. If that's the case, I'm still OK, 'cause before I got your response on how to fix the syntax in question I had created some logic in the loop to get around the issue.

Thanks again!
To the best of my knowledge, the FindFirst method can have compound conditions. If .NoMatch is not working, it might be because the wrong syntax is being used for the data type.

For example, the syntax of your FindFirst statement presents CustID as a text data type:
Expand|Select|Wrap|Line Numbers
  1. FindFirst "[CustID] = ' " & rstOtherTBL!CustID & " ' "  _
  2. & " And [Date] = #" & StartDate & "# "
  3.  
If CustID is a numeric data type, the syntax should have been as follows:
Expand|Select|Wrap|Line Numbers
  1. FindFirst "[CustID] = " & rstOtherTBL!CustID  _
  2. & " And [Date] = #" & StartDate & "# "
  3.  
If syntax of the CustID is not the problem, let me know and I will look into the FindFirst method. .
Jun 5 '07 #7
puppydogbuddy
1,923 Expert 1GB
Here is a link to another thread on this Forum that supports the fact that the FindFirst can be used with 2 variables. See response from Allen Browne, Microsoft MVP Expert.

http://www.thescripts.com/forum/thread204685.html
Jun 6 '07 #8

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

Similar topics

4
by: Skully Matjas | last post by:
I am using the following code (created by the wizard) to allow to bring my form to a particular entery. But when I edit the entery (ex: put new information into a blank cell), it puts that record...
10
by: Steve Jorgensen | last post by:
Microsoft acknowledges a bug with this, but the bug is worse than they say. It turns out that if you use the Like operator without a wildcard on a snapshot type recordset, all sorts of wierd,...
1
by: jphelan | last post by:
I ran a MS Access Analyzer program that suggested changing, "rst.FindFirst strcriteria" to using the, "Seek" instead. I tried making the change. I get a Compile error that says, "Argument is not...
2
by: Nono | last post by:
Hello, I have an Access Database that I want to update using an Excel spreadsheet. When it is new reccords, I know how to do it. Nevertheless when I want to complete the information on a...
2
by: rivka.howley | last post by:
I wrote some code that creates a table with a date/time field at 15-minute intervals. Here's how I create and populate the table With tblDataTemp ..Fields.Append .CreateField("CT_ID", dbLong)...
0
by: JC | last post by:
I have a list box loaded with Student Name, Social Security. When the user click on a specific record, the following code is assigned to the lstStudent1_AfterUpdate procedure. Private Sub...
1
by: BobM | last post by:
i read the thread entitled "Convert Field Value String to Actual Field in Expression" It appeared that the final solutions got moore complex not less complex MY PROBLEM IS: 1. get a value from...
1
by: Justin R | last post by:
Hey I am really stuck and can't figure out what is wrong here is the code line and surrounding code, if anyone can help i would appreciate it. Thanks This first line is the line that has a problem...
25
by: Rick Collard | last post by:
Using DAO 3.6 on an Access 2002 database, I'm getting unexpected results with the FindFirst method. Here's the simple code to test: Public Sub FindIt() Dim db As Database, rs As Recordset...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.