|
-
Dec 8th, 2002, 05:31 AM
#1
Thread Starter
New Member
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
-
Dec 8th, 2002, 06:35 AM
#2
Hyperactive Member
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.
-
Dec 8th, 2002, 07:04 AM
#3
Frenzied Member
VB Code:
Dim Conn As ADODB.Connection
Dim oRs As New ADODB.Recordset
'Make a connection, the following works for MS Acess 2000 Format
Set Conn = New ADODB.Connection
Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\DatabaseName.mdb;"
Conn.Open
'Writing to 2 tables at the same time
Private Sub cmdWriteTables_Click()
Set oRs=New Recordset
oRs.Open "Table1", Conn, adOpenKeyset, adLockOptimistic
oRs.AddNew
oRs!PIN = txtPatID.Text
oRs("Suffering From") = txtDiag.Text
oRs("VisitDateTime") = CDate(Format(Date, "DD/MM/YYYY"))
oRs("Amount") = txtAmount.Text
oRs("Dosage") = strDose
oRs.Update
oRs.Close
oRs.Open "Table2", goCnn, adOpenKeyset, adLockOptimistic
oRs.AddNew
oRs("PIN") = frmWelcome.txtPatID.Text
oRs("VisitDate") = CDate(Format(Date, "DD/MM/YYYY"))
oRs.Update
oRs.Close
Conn.Close
Set oRs=Nothing
Set Conn = Nothing
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|