Setting a Data objects recordset or recordsource in code

I am trying to set a data objects recordsource in code. Basically I am trying to execute a query, return a recordset from the query, and set that to the data object here is my code:

Dim strQuery As String, rsResult As Recordset

On Error GoTo activate_error
strQuery = "SELECT Client.CaseID, Contact.ContactID, Contact.NameF, Contact.NameL, Contact.Address, Contact.City, Contact.State, Contact.Zip, Contact.Phone, Contact.Fax, Contact.Email, Contact.ISP_Member FROM (Client LEFT JOIN ConClient ON Client.CaseID = ConClient.CaseID) LEFT JOIN Contact ON ConClient.ContactID = Contact.ContactID WHERE Client.CaseID = 112578"
'Set rsResult = Project1.Conn.Execute(strQuery)
Set rsResult = dataContact.Database.OpenRecordset(strQuery)

This gives me a type mismatch error. I need to view what information is in the rsResult recordset. I want to do this with the data control so I can link the recordset to text boxes and view the data. Someone please help!!
wilsoadaAsked:
Who is Participating?
 
edwardiiiConnect With a Mentor Commented:
Hi, wilsoada.

Bob's question is a good one.  I don't use DAO; I work with ADO.  In ADO I would need to set up the following code to read from a database:

     Dim MyConn As ADODB.Connection
     Dim MyRecSet As ADODB.Recordset
     Set MyConn = New ADODB.Connection
     Set MyRecSet = New ADODB.Recordset
     MyRecSet.LockType = adLockOptimistic
     MyRecSet.CursorLocation = adUseClient
     MyRecSet.CursorType = adOpenDynamic  
           
     MyConn.ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;Data Source=C\:db.mdb"
     MyConn.Open
     Set MyRecSet = MyConn.Execute("SELECT * FROM Notes")

My example only reads from one table ("Notes") in my "db.mdb" database.  I'm not asking you to switch from DAO to ADO, but with your current coding, don't you need to do Dim a Connection object (e.g. in my code I DIM and SET "MyConn")?
0
 
Bob LambersonSoftware EngineerCommented:
What is "dataContact"
Where are you creating and setting the connection object?

Bob
0
 
wilsoadaAuthor Commented:
I don't think you guys understood the question. The dataContact is a data object in VB6. The ADO connection and everything works fine and executes the SQL statement creates the recordset fine. I am trying to tie the recordset into the data object so I can use it view the data in the recordset. If there is another way to do this please let me know.
0
 
edwardiiiCommented:
Can you share the code/steps you took to create/set up the "data object" (which I'm guessing is "dataContact")?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.