J
jshangkuan
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)
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)