|
-
Feb 27th, 2000, 04:54 AM
#1
Thread Starter
New Member
I would appreciate help with Adding another Table to my ADO project.I have one table,which I display in a datagrid.But can't bring in another table from .mbd file.Any ideas? Thanks!
-
Feb 27th, 2000, 06:12 AM
#2
Hyperactive Member
If you are using a data control for the first grid why don't you just use another data control and set up a second grid?
If you are not using a data control write back and tell me what method you are using and I will forward you some sample code to set up a connection to a second table.
-
Feb 27th, 2000, 07:09 AM
#3
Thread Starter
New Member
Thanks for answering.I'm trying to avoid using a data control.The first connection to table 1 is through using ADO command.For table 2 I would like to do the same.Thanks again.
-
Feb 27th, 2000, 06:01 PM
#4
Hyperactive Member
Below I have a function that you can call by passing a table name or query name or SQL statement as a string, the function will then return you the recordset.
You will need a recordset in the calling procedure as follows (don't forget to reference it in Project References -Microsoft ActiveX DataObjects Library 2.0/2.1)-
Private Sub Command1_Click()
Dim rs as ADODB.Recordset
set rs = Openrs("Table2") 'Where 'Table2'is the table name
'fill text boxes or grid with rs
End Sub
Public Function OpenRs(sSql As String) As Object
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
On Error GoTo ErrorRoutine
cn.Open ' Your Connection string
cn.CursorLocation = adUseClient
rs.Open sSql, cn, adOpenForwardOnly, adLockReadOnly, adCmdUnspecified
Set OpenRs = rs
Set rs.ActiveConnection = Nothing
cn.Close
Set cn = Nothing
Exit Function
ErrorRoutine:
Set OpenRs = rs
MsgBox Err.Description
End Function
Hope this helps, let me know if you have any probs
-
Feb 29th, 2000, 02:53 AM
#5
Thread Starter
New Member
Excellent! Always helps to have a friend somewhere out there in cyberville.
Now I have both tables.Next step is to be able to have them both in synch with my menu.Anything you can throw my way is much appreciated.
-
Feb 29th, 2000, 07:08 AM
#6
Hyperactive Member
Glad it worked out for you.
So what do you mean by 'In sync with my menu' ?
-
Feb 29th, 2000, 08:28 AM
#7
Thread Starter
New Member
I was able to search through the datagrid1 with a menu.Such as First,Next,Last.But with the other table,datagrid2,I cannot get it to reflect datagrid1 when I use the menu.Both tables share a common field.
I hope this sounds a little clearer.Thanks again.
-
Feb 29th, 2000, 05:48 PM
#8
Hyperactive Member
Ok Dean I think I get you but I need to see your code, show me where you are trying to refresh the 2 grids, an dyour credit card number!
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
|