Chat with a LIVE Microsoft Access Expert!
 
       
 

         

   

Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
 
Chat with a LIVE Microsoft Access Expert!
Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 06-19-2007, 06:05 AM
feets feets is offline
Registered User
 
Join Date: Jan 2007
Posts: 12
feets is on a distinguished road
Unable to assign Ado recordset to form

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

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
Reply With Quote
Sponsored Links
  #2  
Old 06-19-2007, 06:51 AM
boblarson's Avatar
boblarson boblarson is online now
Super Moderator
 
Join Date: Jan 2001
Posts: 22,003
boblarson is a name known to allboblarson is a name known to allboblarson is a name known to allboblarson is a name known to allboblarson is a name known to allboblarson is a name known to all
You have this:
Dim rsVisit As ADODB.Recordset

But you never instantiate it (and ADO doesn't like that):

Set rsVisit = New ADODB.Recordset

you need to do that first before the

Set rsVisit = cmd.Execute (and I'm not sure about this one anyway as you need to "open" the recordset not set it to the cmd.Excecute. rsVisit.Open ...etc.
__________________
Thanks,

Bob Larson

Free samples, tools and tutorials (including Auto Frontend Update Enabling Tool)

"Have you tried turning it off and on again?"
Reply With Quote
  #3  
Old 06-20-2007, 01:11 AM
feets feets is offline
Registered User
 
Join Date: Jan 2007
Posts: 12
feets is on a distinguished road
Quote:
Originally Posted by boblarson View Post
You have this:
Dim rsVisit As ADODB.Recordset

But you never instantiate it (and ADO doesn't like that):

Set rsVisit = New ADODB.Recordset

you need to do that first before the

Set rsVisit = cmd.Execute (and I'm not sure about this one anyway as you need to "open" the recordset not set it to the cmd.Excecute. rsVisit.Open ...etc.
Thanks for your advice so far. As suggested by you and others I created a new instance and then opened the recordset assigning it to the form's recordset.

This gives me all the records from the local table, what I want to do now is from the main form select criteria, which after updating refreshes the recordset showing the results.

I had tried to create a query event on the subform which would run the select query. However when I update the combo box I could not get it run the event. form_sbfrmCR_Visit.query???

What would be the best way to achieve this?
Reply With Quote
  #4  
Old 06-20-2007, 06:07 AM
boblarson's Avatar
boblarson boblarson is online now
Super Moderator
 
Join Date: Jan 2001
Posts: 22,003
boblarson is a name known to allboblarson is a name known to allboblarson is a name known to allboblarson is a name known to allboblarson is a name known to allboblarson is a name known to all
If you create a SQL string and assign it to, say strSQL and then use

rst.Open strSQL, strcnn, adOpenDynamic, adLockOptimistic

and then you can set the subform's recordsource to rst
__________________
Thanks,

Bob Larson

Free samples, tools and tutorials (including Auto Frontend Update Enabling Tool)

"Have you tried turning it off and on again?"
Reply With Quote
Sponsored Links
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to return to Form Matt Greatorex Forms 12 07-31-2006 06:40 AM
Form Recordset Problem modest Modules & VBA 1 04-22-2005 08:55 PM
Requery and/or Update problem with a form and recordset mbentley Modules & VBA 6 08-17-2004 01:17 PM
Set ADO recordset equal to subform recordset Rob601 Modules & VBA 2 01-26-2004 12:39 PM
Displaying a custom recordset on a form stuartmatheson Modules & VBA 0 03-07-2002 06:29 PM


All times are GMT -8. The time now is 09:53 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
(c) copyright 2009 Access World