Results 1 to 3 of 3

Thread: saving into 2 tables with 1 form

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Posts
    4

    saving into 2 tables with 1 form

    hello, thanks for looking into this.

    Well, in access, I've got a form1. that adds records to table1.
    What I'm interested in is to use form1 and saves to table1 and table2 as well.

    it sounds ridiculously easy, but I've yet to find the code for it.

    I would be a great help if anyone could explain how the form relates to the table. your help is really appreciated. Thanks

  2. #2
    Hyperactive Member
    Join Date
    Sep 2001
    Location
    Europe
    Posts
    289
    Use the same code you have for table1 twice instead of once and change whatever is needed to table2. Post your code because the question is indeed vague.

  3. #3
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396
    VB Code:
    1. Dim Conn As ADODB.Connection
    2. Dim oRs As New ADODB.Recordset
    3.  
    4. 'Make a connection, the following works for MS Acess 2000 Format
    5.  Set Conn = New ADODB.Connection
    6.     Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\DatabaseName.mdb;"
    7.  
    8. Conn.Open
    9. 'Writing to 2 tables at the same time
    10.  
    11. Private Sub cmdWriteTables_Click()
    12. Set oRs=New Recordset
    13. oRs.Open "Table1", Conn, adOpenKeyset, adLockOptimistic
    14.         oRs.AddNew
    15.         oRs!PIN = txtPatID.Text
    16.         oRs("Suffering From") = txtDiag.Text
    17.         oRs("VisitDateTime") = CDate(Format(Date, "DD/MM/YYYY"))
    18.         oRs("Amount") = txtAmount.Text
    19.         oRs("Dosage") = strDose
    20.         oRs.Update
    21.         oRs.Close
    22. oRs.Open "Table2", goCnn, adOpenKeyset, adLockOptimistic
    23.         oRs.AddNew
    24.         oRs("PIN") = frmWelcome.txtPatID.Text
    25.         oRs("VisitDate") = CDate(Format(Date, "DD/MM/YYYY"))
    26.         oRs.Update
    27.         oRs.Close
    28.         Conn.Close
    29.         Set oRs=Nothing
    30.         Set Conn = Nothing
    31. End Sub

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