From post #4…
Code:
Function DAORecordsetExample()
Dim rs As DAO.Recordset
Dim strSQL As String
strSQL = "SELECT DISTINCT Groups.GroupID, Groups.GroupName, Groupings.GroupPhoneBroadcast"
strSQL = strSQL & " FROM Groups INNER JOIN Groupings ON Groups.GroupID = Groupings.GroupID"
strSQL = strSQL & " WHERE (((Groupings.GroupPhoneBroadcast) = True)) ORDER BY Groups.GroupName;"
Set rs = DBEngine(0)(0).OpenRecordset(strSQL)
'Set rs = DBEngine(0)(0).OpenRecordset(QBroadcastGroups)
Do While Not rs.EOF
Debug.Print rs!GroupName
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
End Function
In the line which is commented out, QbroadcastGroups (without quotes) is not declared and would not have compiled unless QbroadcastGroups (as a variable) is declared outside the procedure or Option Explicit was turned off at the time.
Post #1
>>Using Allen's DAO sample as a frame of reference<<
Post #3
>> But VBA debug reports that the query QBroadcastGroups is "Empty".<<
Post #5
>>Put the table or query name within quotes as in the example shown in link.<<
Post #6
>>I have no idea how I'd dismissed that thought earlier.<<
>> It has to be the way OpenRecordset examines its parameter.<<
Post #7.
>>QbroadcastGroups is a variable and without Option Explicit it is defined as a Variant and initialized to Empty.<<
Post #9
>> Just as a FYI, I always code my modules "Option Explicit" so I'll catch problems whenever I compile.<<
Please explain the following:-
Why are you using Allen's DAO sample as a frame of reference in post #1?
Why did debug report Empty in post #3?
How the quotes were missing around QbroadcastGroups in post #4.
The suggested fix in post #5 worked.
That fix was confirmed in post #6.
Why must it be in post #6.
Why you would need to ‘always code my modules’ in post #9 if it was turned on by default?
Are you now saying QbroadcastGroups as a variable (without the quotes) was declared outside of the procedure?
Are you still saying that it must be something else?
Chris.