VBA DAO.Recordset not returning same results as Access Query (1 Viewer)

boblarson

Smeghead
Local time
Yesterday, 20:21
Joined
Jan 12, 2001
Messages
32,059
Give me an example of what you are typing into the Service Text box.
 

Chauncey7

Registered User.
Local time
Yesterday, 20:21
Joined
Jun 28, 2012
Messages
15
This is what the SQL Statement comes out to be:

Code:
[DataType] <> 'CDMD' AND [VALVE_NO] = 'XX-X-13' AND [SYSTEM] = 'OIL TANK' AND [LOCATION] = '1-11-11-X' AND [SERVICE] = 'VALVE,1 1/2'' BALL,FO STOR TK 5-26-0-F'


VALVE,1 1/2'' BALL,FO STOR TK 5-26-0-F'

is the service
 

boblarson

Smeghead
Local time
Yesterday, 20:21
Joined
Jan 12, 2001
Messages
32,059
This is what the SQL Statement comes out to be:

Code:
[DataType] <> 'CDMD' AND [VALVE_NO] = 'XX-X-13' AND [SYSTEM] = 'OIL TANK' AND [LOCATION] = '1-11-11-X' AND [SERVICE] = 'VALVE,1 1/2'' BALL,FO STOR TK 5-26-0-F'


VALVE,1 1/2'' BALL,FO STOR TK 5-26-0-F'

is the service

Well, that would explain it. It would be the double quote in the text which is causing the problem.

You need to change your code (to replace any quotes):

strcriteria = "[DataType] <> '" & Form_CompareFullSubform.DataType & "' AND " & "[VALVE_NO] = '" & Form_CompareFullSubform.VALVE_NO & "' AND " & "[SYSTEM] = '" & Form_CompareFullSubform.SYSTEM & "' AND " & "[LOCATION] = '" & Form_CompareFullSubform.Location & "' AND " & "[SERVICE] = '" & Replace(Form_CompareFullSubform.SERVICE, Chr(34), """") & "'"


Be sure to do that for any of them that might have quotes in the entries being used.
 

Chauncey7

Registered User.
Local time
Yesterday, 20:21
Joined
Jun 28, 2012
Messages
15
Bob that didn't work either. The criteria string actually does work for others that have quotes in the SERVICE. I replaced the code anyway, but still to no avail. I am at my whits end with this thing.:banghead:
 

vbaInet

AWF VIP
Local time
Today, 04:21
Joined
Jan 22, 2010
Messages
26,374
Upload a stripped down version of your db, let's see it run.
 

Users who are viewing this thread

Top Bottom