I'm
using the ADO database object model so the DAO/ADO issue shouldn't be a
problem. I'm trying to select all records in a column of a table and
display them. here is the code
Sub SelectAllFields()
Dim strSQL As String
'Query, selecting all fields from the ClientList table
strSQL = "Select * FROM ClientList"
'Pass arguments to Preview
PreviewRecord (strSQL)
End Sub
Sub PreviewRecord(strSQL As String)
Dim rst1 As Connection
Dim fld1 As Field
Dim intl As Integer
Set rstl = CurrentProject.Connection
rst1.Execute strSQL <-----The Error is here ****
'Loop through first 10 records,
'and print all non-OLEobject fields to the
'immediate window
intl = 1
Do Until rst1.EOF
Debug.Print "Output for record: " & intl
For Each fld1 In rst1.Fields
If Not (fld1.Type = adLongVarBinary) Then
Debug.Print String(5, " "
& fld1.Name & " = " & fld1.Value
End If
Next fld1
rst1.MoveNext
If int1 >= 10 Then
Exit Do
Else
intl = intl + 1
Debug.Print
End If
Loop
'Clean up objects
rst1.Close
Set rest1 = Nothing
End Sub
When I add a watch rst1 is never defined by the "Set rst1" statement.
Error message: Runtime Error 91: Object variable or With variable not set.
Why isn't my variable being set?
using the ADO database object model so the DAO/ADO issue shouldn't be a
problem. I'm trying to select all records in a column of a table and
display them. here is the code
Sub SelectAllFields()
Dim strSQL As String
'Query, selecting all fields from the ClientList table
strSQL = "Select * FROM ClientList"
'Pass arguments to Preview
PreviewRecord (strSQL)
End Sub
Sub PreviewRecord(strSQL As String)
Dim rst1 As Connection
Dim fld1 As Field
Dim intl As Integer
Set rstl = CurrentProject.Connection
rst1.Execute strSQL <-----The Error is here ****
'Loop through first 10 records,
'and print all non-OLEobject fields to the
'immediate window
intl = 1
Do Until rst1.EOF
Debug.Print "Output for record: " & intl
For Each fld1 In rst1.Fields
If Not (fld1.Type = adLongVarBinary) Then
Debug.Print String(5, " "
End If
Next fld1
rst1.MoveNext
If int1 >= 10 Then
Exit Do
Else
intl = intl + 1
Debug.Print
End If
Loop
'Clean up objects
rst1.Close
Set rest1 = Nothing
End Sub
When I add a watch rst1 is never defined by the "Set rst1" statement.
Error message: Runtime Error 91: Object variable or With variable not set.
Why isn't my variable being set?