|
-
Jul 15th, 2009, 04:24 PM
#1
Thread Starter
New Member
How do I data bind a second ADO object in VB6?
I don't ask for help all too often, so in case this is a n00b question for you guys, I am sorry for wasting your time, but I have been busting my *** trying to figure this out for 2 days now.
I have a mySQL database and am using VB6 and the ODBC 5.1 Connector to communicate with it. I have recently discovered the ADO object and the ability to data bind objects to the record sets it works with. That works great for me. Like in MS Access, I would like to create a sub form / sub query as a second ADO object. The second object is the one that is giving me problems.
TABLE 1 (tblBusinesses)
Company
CompanyID (PK)
Address
City
etc
TABLE 2 (tblClients)
CompanyID
ContactName
ContactEmail
ContactPhone
BackupBattery
LiquorSystem
Notes
I realize that with the above example I could cheat and merge the tables into one, however I have more tables and entities in the DB and need to know how to properly work with them.
Currently my RecordSource property for my second ADO object is:
Code:
SELECT * FROM tblClients INNER JOIN tblBusinesses ON tblClients.CompanyID=tblBusinesses.CompanyID
This works (coincidentally I believe) for the first record, but when I goto next record in the first ADO, the second ADO should automatically update it's values. In MS Access this kind of binding will work, even though it doesn't make alot of sense, as you save it as a query and then turn that query into a subform on your main form, however, there must be a similar or proper way of getting this to work. I have downloaded a ton of e-books and none of them explain how to visually use a second ADO control and data bind text boxes, combo boxes, etc to the control's data.
Alternatively, I tried to adjust my SQL statement to use the WHERE clause instead of an INNER JOIN, plus I tried making 2 separate forms, one ADO control on each form. I created a button on the first form with the following code:
Code:
Private Sub Command1_Click()
Dim nf As New Form2
nf.txtCompany.Text = Me.txtCompany.Text
nf.clients.RecordSource = "SELECT * FROM dennisk_rsi.tblClients WHERE dennisk_rsi.tblClients.Company='" & nf.txtCompany.Text & "'"
nf.clients.Recordset.Requery
nf.Show
End Sub
This also doesn't work. I am truely lost. Please help me figure this out. I'd appreciate any help offered.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|