I think a bit of background would be useful first, before discussing the coding issue.
I have an Adp connecting to a Sql 2000 Server. The purpose of the front end is to record visits to premises.
My users have laptops so therefore will not always have a connection to the Sql backend. Therefore when a visit record is inserted, it is also inserted in a table on a local mdb file held in their my Documents folder. The purpose is to view previous visits whilst offline.
My problem is that I can program and open a connection to the local mdb. I can run a select query which is assigned to a recordset object. What I can't do is assign a form's recordset property to the recordset I have created.
I get Run time error '91' Object variable or with block not set. Something I don't really understand, so I would appreciate any attempt to help me comprehend.
Below is the code I'm using when the form loads
I have an Adp connecting to a Sql 2000 Server. The purpose of the front end is to record visits to premises.
My users have laptops so therefore will not always have a connection to the Sql backend. Therefore when a visit record is inserted, it is also inserted in a table on a local mdb file held in their my Documents folder. The purpose is to view previous visits whilst offline.
My problem is that I can program and open a connection to the local mdb. I can run a select query which is assigned to a recordset object. What I can't do is assign a form's recordset property to the recordset I have created.
I get Run time error '91' Object variable or with block not set. Something I don't really understand, so I would appreciate any attempt to help me comprehend.
Below is the code I'm using when the form loads
Code:
Private Sub Form_Load()
Dim cmd As ADODB.Command
Dim rsVisit As ADODB.Recordset
Dim frm As Form_sbFrm_ViewCR
Dim objVisit As Object
Dim strcnn As String
Dim strMdbPath As String
Dim strDbName As String
' Calls Function to Find Path of MyDocumenrs
strMdbPath = SpecFolder(CSIDL_Personal)
strDbName = "\wsrsVisits.mdb"
strMdbPath = strMdbPath + strDbName
strcnn = "Provider=Microsoft.jet.oledb.4.0;"
strcnn = strcnn & "Data Source= " & strMdbPath & ";"
strcnn = strcnn & "Persist Security Info=False"
Set cmd = New ADODB.Command
cmd.ActiveConnection = strcnn
cmd.CommandType = adCmdText
cmd.CommandText = "Select VisitID,DateOfVisit,Method,Reason From tblCrVisit"
Set rsVisit = cmd.Execute
Me.Recordset = rsVisit