• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

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!!
  • 2
1 Solution
Bob LambersonSoftware EngineerCommented:
What is "dataContact"
Where are you creating and setting the connection object?

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"
     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")?
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.
Can you share the code/steps you took to create/set up the "data object" (which I'm guessing is "dataContact")?

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now