comart
April 9th, 2001, 11:20 AM
I am creating my recordset using the execute method of the command object. When I try to print the fields from the recordset, I get an error message stating that I'm either at EOF or BOF. What am I doing wrong?
'recordset and connection variables
Dim cmd As Command
Dim rs As Recordset
Dim Cnn As Connection
Dim strCnn As String
'record variables
Dim strPrompt As String
Dim strName As String
Dim strParameter As String
Dim prm As Parameter
Set Cnn = New Connection
Set cmd = New Command
strPrompt = "Enter an author's name (e.g., Cox,Joyce): "
strName = Trim(InputBox(strPrompt, "ActiveCommandX Example"))
strCnn = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Program Files\Microsoft Visual Studio\VB98\Biblio.mdb"
'create SQL command string
cmd.CommandText = "SELECT * FROM [All Titles] WHERE Author = ?"
Set prm = cmd.CreateParameter("AuthorName", adChar, adParamInput, 50, strName)
cmd.Parameters.Append prm
Cnn.Open strCnn
Set cmd.ActiveConnection = Cnn
'create the recordset by executing command string
Set rs = cmd.Execute
Debug.Print "Author = '" & rs!Author & "' Title= '" & rs!Title
' clean up
rs.Close
Cnn.Close
Set rs = Nothing
Set Cnn = Nothing
'recordset and connection variables
Dim cmd As Command
Dim rs As Recordset
Dim Cnn As Connection
Dim strCnn As String
'record variables
Dim strPrompt As String
Dim strName As String
Dim strParameter As String
Dim prm As Parameter
Set Cnn = New Connection
Set cmd = New Command
strPrompt = "Enter an author's name (e.g., Cox,Joyce): "
strName = Trim(InputBox(strPrompt, "ActiveCommandX Example"))
strCnn = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Program Files\Microsoft Visual Studio\VB98\Biblio.mdb"
'create SQL command string
cmd.CommandText = "SELECT * FROM [All Titles] WHERE Author = ?"
Set prm = cmd.CreateParameter("AuthorName", adChar, adParamInput, 50, strName)
cmd.Parameters.Append prm
Cnn.Open strCnn
Set cmd.ActiveConnection = Cnn
'create the recordset by executing command string
Set rs = cmd.Execute
Debug.Print "Author = '" & rs!Author & "' Title= '" & rs!Title
' clean up
rs.Close
Cnn.Close
Set rs = Nothing
Set Cnn = Nothing