This code errors at the Set rstTL = db.OpenRecordset(strQ2, dbOpenDynaset, dbReadOnly)
I can't figure out why. Is there a special syntax for calling a query in a recordset? The help files show that its possible though do not show specifically how to do this by calling a variable. Perhaps quotations are required or some type of string conversion, though I tried some of this and couldnt find a working combination. I've tried various options replacing the dbopendynaset, including nothing and still get the same result.
The error I get is type mismatch though when I check the values they look correct to me. I've tried to use the strQ3 option as well but I get the same error. Perhaps its something in the dlookup it doesn't like but the dlookup returns the value I'd expect and the query does exist (it is a distinctrows query and is returning values). Does anyone see my problem?
Dim rstTL As ADODB.Recordset
Dim strTL As String
Dim RefID As Integer
Dim db As DAO.Database
Dim strQ As String
Dim strQ2 As String
Dim strQ3 As String
Dim IDN As Integer
'Create Recordset of selection for list of Unique team Leaders
Set db = CurrentDb
For RefID = 1 To 19
' Do for each Team Lead in selection
strQ2 = DLookup("DCQuery", "tblReference", "ID=" & RefID & "") & "_N"
strQ3 = "SELECT * FROM " & strQ2 & ""
Set rstTL = db.OpenRecordset(strQ2, dbOpenDynaset, dbReadOnly)
I can't figure out why. Is there a special syntax for calling a query in a recordset? The help files show that its possible though do not show specifically how to do this by calling a variable. Perhaps quotations are required or some type of string conversion, though I tried some of this and couldnt find a working combination. I've tried various options replacing the dbopendynaset, including nothing and still get the same result.
The error I get is type mismatch though when I check the values they look correct to me. I've tried to use the strQ3 option as well but I get the same error. Perhaps its something in the dlookup it doesn't like but the dlookup returns the value I'd expect and the query does exist (it is a distinctrows query and is returning values). Does anyone see my problem?
Dim rstTL As ADODB.Recordset
Dim strTL As String
Dim RefID As Integer
Dim db As DAO.Database
Dim strQ As String
Dim strQ2 As String
Dim strQ3 As String
Dim IDN As Integer
'Create Recordset of selection for list of Unique team Leaders
Set db = CurrentDb
For RefID = 1 To 19
' Do for each Team Lead in selection
strQ2 = DLookup("DCQuery", "tblReference", "ID=" & RefID & "") & "_N"
strQ3 = "SELECT * FROM " & strQ2 & ""
Set rstTL = db.OpenRecordset(strQ2, dbOpenDynaset, dbReadOnly)