tranchemontaigne
Registered User.
- Local time
- Today, 04:06
- Joined
- Aug 12, 2008
- Messages
- 203
I have what I think should be a relatively simple task that is particularly difficult to implement. I'm using a VBA module to dynamically build a SQL statement and assign it to the strSQL variable.
The query runs perfectly from a query design window and pulls a little more than 1,000 records, yet when I attempt to build an ADODB recordset using this SQL, the recordset always comes up empty.
Here's the basic code
It's hard to tell from this post, but there are white space characters at the end of each row in the strSQL statement above.
I don't think I'm hitting a hard character limit for the length of a SQL statement....
What's going wrong, or more importantly, what can I do to fix this?
Code:
SELECT
EIWS_PFC_SURVEY_STANDARDIZED.*
, EIWS_PFC_SURVEY_PERSON.Event
, EIWS_PFC_SURVEY_PERSON.Respondent_ID
, EIWS_PFC_SURVEY_PERSON.Consent
, EIWS_PFC_SURVEY_PERSON.Eligible
, EIWS_PFC_SURVEY_PERSON.Age
, EIWS_PFC_SURVEY_PERSON.Date_Survey_Imported
, EIWS_PFC_SURVEY_PERSON.Date_Sent_to_LIMS
FROM
EIWS_PFC_SURVEY_STANDARDIZED INNER JOIN
EIWS_PFC_SURVEY_PERSON ON
EIWS_PFC_SURVEY_STANDARDIZED.UniqueKey =
EIWS_PFC_SURVEY_PERSON.EWIS_PFC_Survey_UniqueKey
WHERE (((EIWS_PFC_SURVEY_PERSON.Event) Like '*') AND
((EIWS_PFC_SURVEY_STANDARDIZED.P_Worked) In (1,0,88,99)) AND
((EIWS_PFC_SURVEY_STANDARDIZED.P_Lived) In (1,0,88,99)) AND
((EIWS_PFC_SURVEY_STANDARDIZED.P_ChildCare) In (1,0,88,99)) AND
((EIWS_PFC_SURVEY_STANDARDIZED.P_Mother) In (1,0,88,99)) AND
((EIWS_PFC_SURVEY_STANDARDIZED.Am In (1,0,88,99)) AND
((EIWS_PFC_SURVEY_STANDARDIZED.Ma) In (1,0,88,99)) AND
((EIWS_PFC_SURVEY_STANDARDIZED.Me) In (1,0,88,99)) AND
((EIWS_PFC_SURVEY_STANDARDIZED.Li) In (1,0,88,99)) AND
((EIWS_PFC_SURVEY_STANDARDIZED.Be) In (1,0,88,99)) AND
((EIWS_PFC_SURVEY_PERSON.Date_Survey_Imported) Between #9/9/1999# And #9/9/2099#) );
The query runs perfectly from a query design window and pulls a little more than 1,000 records, yet when I attempt to build an ADODB recordset using this SQL, the recordset always comes up empty.
Here's the basic code
Code:
'// Declarations from top of module include
Option Compare Database
Option Explicit
'// declarations within the function include
Dim strSQL As String
Dim rst1 As ADODB.Recordset
'// block of code that builds a dynamic SQL statement using strSQL
'// goes here
'//
'// a break point is used to debug.print the contents of strSQL at run time
'// and copy/paste it into a query design window where it runs perfectly
'//
'// next the rst1 recordset is build using strSQL
Set rst1 = New ADODB.Recordset
rst1.ActiveConnection = CurrentProject.Connection
rst1.Open strSQL ', , adOpenForwardOnly, adLockOptimistic
'// breakpoint immediately after the recordset is opened confirms that
'// rst1.eof = true
It's hard to tell from this post, but there are white space characters at the end of each row in the strSQL statement above.
I don't think I'm hitting a hard character limit for the length of a SQL statement....
What's going wrong, or more importantly, what can I do to fix this?