Beginning VBA (reference book) question (SOLVED)
Hello,
I am currently working on the reference book "Beginning Access VBA 2007" by Denise Gosnell and am stuck at attempting to get the code from Chapter 13 to work. The code is as follows:
This is code connecting to a recordset on another DB. I have checked the connection string which is working great but the question is: Once the connection is made there is no recordset returned to the calling sub and an "object variable or with block variable" error is returned.
I notice that after the "With/end With" the code closes the connection prior to returning the recordset. Is this correct?
I did note as well that Bob Larson is a member of the Wrox press community site so, if your here Bob
As usual all help appreciated.
This has been solved.
There is a line of code missing from the book. In the calling function the line returning the recordset is missing.
Hello,
I am currently working on the reference book "Beginning Access VBA 2007" by Denise Gosnell and am stuck at attempting to get the code from Chapter 13 to work. The code is as follows:
Code:
Function ProcessRecordset(strSQLStatement As String) As ADODB.Recordset
On Error GoTo HandleError
'open the connection to the database
Call OpenDbConnection
'create a new instance of a recordset
Dim rsCont As New ADODB.Recordset
'set various properties of the recordset
With rsCont
'specify a cursortype and lock type that will allow updates
.CursorType = adOpenKeyset
.CursorLocation = adUseClient
.LockType = adLockBatchOptimistic
'populate the recordset based on SQL statement
.Open strSQLStatement, cnConn
'disconnect the recordset
.ActiveConnection = Nothing
'sort the recordset
End With
'close the connection to the database
Call CloseDbConnection
'return the recordset
Set ProcessRecordset = rsCont
Exit Function
HandleError:
GeneralErrorHandler Err.Number, Err.Description, DB_LOGIC, "ProcessRecordset"
Exit Function
End Function
This is code connecting to a recordset on another DB. I have checked the connection string which is working great but the question is: Once the connection is made there is no recordset returned to the calling sub and an "object variable or with block variable" error is returned.
I notice that after the "With/end With" the code closes the connection prior to returning the recordset. Is this correct?
I did note as well that Bob Larson is a member of the Wrox press community site so, if your here Bob

As usual all help appreciated.
This has been solved.
There is a line of code missing from the book. In the calling function the line returning the recordset is missing.
Last edited: