PC Review


Reply
Thread Tools Rate Thread

Data mismatch criteria error ?

 
 
jshangkuan@gmail.com
Guest
Posts: n/a
 
      21st Jan 2007
I have a really simple VBA code, and I have a "Data mismatch criteria
error" that I have no idea why it occurs. I have a table "MyTable"
where all the fields are text. When I run the code, it errors on the
last line when I set rs. I think this is because of the CurrentDb. I
have another error like this with another function, and I am not sure
why this occurs.

Your help would be appreciated. I also tried docmd.execute(mySQLstr),
which also doesn't work. What is the difference?

Private Sub cmdFindRecords_Click()
MySQLStr = "SELECT MyTable.* FROM MyTable WHERE ("

If Not IsNull(Me.Field1) Then
MySQLStr = MySQLStr & " ((MyTable.Field1) ='" &
[Forms]![MySearchForm]![Field1] & "') And"
End If
If Not IsNull(Me.Field2) Then
MySQLStr = MySQLStr & " ((MyTable.Field2) ='" &
[Forms]![MySearchForm]![Field2] & "') And"
End If

End If

MySQLStr = MySQLStr & "((MyTable.Field1) > ''));"

Set rs = CurrentDb.OpenRecordset(MySQLStr)

 
Reply With Quote
 
 
 
 
Allen Browne
Guest
Posts: n/a
 
      21st Jan 2007
You don't show the declaration line for rs, but try adding this line to the
top of your procedure:
Dim rs AS DAO.Recordset

If that fails also, you probably need to add a reference to:
Microsoft DAO 3.6 Library
It's no the Tools menu, under References.

More info on references here:
http://allenbrowne.com/ser-38.html


--
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.

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have a really simple VBA code, and I have a "Data mismatch criteria
> error" that I have no idea why it occurs. I have a table "MyTable"
> where all the fields are text. When I run the code, it errors on the
> last line when I set rs. I think this is because of the CurrentDb. I
> have another error like this with another function, and I am not sure
> why this occurs.
>
> Your help would be appreciated. I also tried docmd.execute(mySQLstr),
> which also doesn't work. What is the difference?
>
> Private Sub cmdFindRecords_Click()
> MySQLStr = "SELECT MyTable.* FROM MyTable WHERE ("
>
> If Not IsNull(Me.Field1) Then
> MySQLStr = MySQLStr & " ((MyTable.Field1) ='" &
> [Forms]![MySearchForm]![Field1] & "') And"
> End If
> If Not IsNull(Me.Field2) Then
> MySQLStr = MySQLStr & " ((MyTable.Field2) ='" &
> [Forms]![MySearchForm]![Field2] & "') And"
> End If
>
> End If
>
> MySQLStr = MySQLStr & "((MyTable.Field1) > ''));"
>
> Set rs = CurrentDb.OpenRecordset(MySQLStr)
>


 
Reply With Quote
 
Allen Browne
Guest
Posts: n/a
 
      21st Jan 2007
You also asked about the difference between OpenRecordset and Execute.

OpenRecordset() is like an ordinary SELECT query, except that you don't see
the results in a query window. Instead, they exist only in memory, where you
can walk through the records, and examine or edit the fields.

Execute works like an action query (Append/Delete/Update/Make Table.) When
you run one of these queries you don't see any results: just information
about what records were changed. WIth DoCmd, you can use RunSQL, but not
Execute. For more info on the difference between RunSQL and Execute, see:
http://allenbrowne.com/ser-60.html

--
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.

"Allen Browne" <(E-Mail Removed)> wrote in message
news:%23a8%(E-Mail Removed)...
> You don't show the declaration line for rs, but try adding this line to
> the top of your procedure:
> Dim rs AS DAO.Recordset
>
> If that fails also, you probably need to add a reference to:
> Microsoft DAO 3.6 Library
> It's no the Tools menu, under References.
>
> More info on references here:
> http://allenbrowne.com/ser-38.html
>
>
> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>I have a really simple VBA code, and I have a "Data mismatch criteria
>> error" that I have no idea why it occurs. I have a table "MyTable"
>> where all the fields are text. When I run the code, it errors on the
>> last line when I set rs. I think this is because of the CurrentDb. I
>> have another error like this with another function, and I am not sure
>> why this occurs.
>>
>> Your help would be appreciated. I also tried docmd.execute(mySQLstr),
>> which also doesn't work. What is the difference?
>>
>> Private Sub cmdFindRecords_Click()
>> MySQLStr = "SELECT MyTable.* FROM MyTable WHERE ("
>>
>> If Not IsNull(Me.Field1) Then
>> MySQLStr = MySQLStr & " ((MyTable.Field1) ='" &
>> [Forms]![MySearchForm]![Field1] & "') And"
>> End If
>> If Not IsNull(Me.Field2) Then
>> MySQLStr = MySQLStr & " ((MyTable.Field2) ='" &
>> [Forms]![MySearchForm]![Field2] & "') And"
>> End If
>>
>> End If
>>
>> MySQLStr = MySQLStr & "((MyTable.Field1) > ''));"
>>
>> Set rs = CurrentDb.OpenRecordset(MySQLStr)


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
'Data type mismatch in criteria expression' Error mark Microsoft Access 7 8th Jul 2008 03:00 PM
Error 3464 Data Type mismatch in criteria expression charleswoods via AccessMonster.com Microsoft Access VBA Modules 2 3rd Jan 2007 07:38 PM
Error 3464 Data type mismatch in criteria expression =?Utf-8?B?SGVsZW4=?= Microsoft Access Queries 3 2nd May 2006 11:14 PM
error Data type mismatch in criteria expression on sum Igor Barbaric Microsoft Access 1 27th Jan 2006 08:23 AM
Data Mismatch Criteria Expression Error Sondra Microsoft Access Queries 5 18th Jan 2005 12:00 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:37 AM.