Results 1 to 8 of 8

Thread: add another table

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Location
    Los Angeles, California
    Posts
    4

    Post

    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!

  2. #2
    Hyperactive Member
    Join Date
    Feb 2000
    Posts
    284

    Post

    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.

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Location
    Los Angeles, California
    Posts
    4

    Post

    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.

  4. #4
    Hyperactive Member
    Join Date
    Feb 2000
    Posts
    284

    Post

    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

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Location
    Los Angeles, California
    Posts
    4

    Post

    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.

  6. #6
    Hyperactive Member
    Join Date
    Feb 2000
    Posts
    284

    Post

    Glad it worked out for you.

    So what do you mean by 'In sync with my menu' ?

  7. #7

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Location
    Los Angeles, California
    Posts
    4

    Post

    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.

  8. #8
    Hyperactive Member
    Join Date
    Feb 2000
    Posts
    284

    Post

    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
  •  



Click Here to Expand Forum to Full Width