Results 1 to 4 of 4

Thread: 2 Databases 1 form Moving things around HELP PLESE!

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Location
    Brantford Onatrio Canada
    Posts
    5

    Question

    Actualy i'm buinding a form that has 2 data controls linked to two diffrent databases, and I have a dbgrid that is linked to an empty database, I want to add diffrent things from the 2 data controls to the dbgrid, so far, i'm getting no where I was hoping to get in touch with Karl Moore, beacuse of his "world famous" database tutorial. It actuly is easy to learn database with that tutorial.
    Please reply or e-mail me with examples or ways I can do this. Thank you..
    From your friendly neibourhood
    [email protected]

  2. #2
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Thumbs up

    Then May be you can add what ever you want from the two data control into the empty database then just refersh your dbgrid.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Location
    Brantford Onatrio Canada
    Posts
    5

    Arrow can you give me a code example

    i'm not quite sure what your talking about, i understand, but codewise it just does not click in you know...
    From your friendly neibourhood
    [email protected]

  4. #4
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Lightbulb Sample Code

    Hi Spidie-Man, here is a sample code hope it can help you.

    By the way, the Data1 and Data2 Data Control is useless in my code and I just ignore it.

    Code:
    Private Sub Form_Load()
    'Assume your database name is:
    '1. database1.mdb -> tblCustomer .. Fields(ID, Name, Add1, Add2, Telephone)
    '2. database2.mdb -> tblOrder .. Fields(ID, Orderno, TotalOrder, Amount)
    '3. database3.mdb -> tblFinal .. Fields(ID, Name, Add1, Add2, Telephone, OrderNo, TotalOrder, Amount)
    
    'Initialize all the data control
    Data3.DatabaseName = App.Path & "\database3.mdb"
    Data3.RecordSource = "tblFinal"
    Data3.Refresh
    End Sub
    
    Private Sub cmdCombine_Click()
    Dim Db As DAO.Database
    Dim MySql As String
    
    Set Db = DBEngine.Workspaces(0).OpenDatabase(App.Path & "\database3.mdb", False, False)
    Db.Execute "DELETE * FROM tblFinal;"
    'Copy all the records from database1 and database2 into database3
    MySql = "INSERT INTO tblFinal (ID, Name, Add1, Add2, Telephone, OrderNo, TotalOrder, Amount) " & _
            "SELECT tblCustomer.ID, Name, Add1, Add2, Telephone, OrderNo, TotalOrder, Amount FROM [" & App.Path & "\database1.mdb].tblCustomer LEFT JOIN [" & App.Path & "\database2.mdb].tblOrder " & _
            "ON tblCustomer.ID = tblOrder.ID " & _
            "ORDER BY tblCustomer.ID ASC;"
    Db.Execute MySql
    Db.Close
    Set Db = Nothing
    Data3.Refresh
    End Sub
    [Edited by Chris on 06-16-2000 at 07:40 AM]

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