daffelito
09-06-2008, 12:26 AM
Hi, I have this code on a button so that i in a single push of a button enters data into two tables that are in relation to eachother.
But i dont get it to work.
The tables looks like this:
tblPumpsort
id - counter (primary key and parent to table 2)
<more stuff>
tblPumpsortEl
id - counter (primary key)
ProduktID (child to id in tblPumpsort)
El
then i have some code to the addreccord button that looks like this:
Private Sub laggtillpump_Click()
On Error GoTo Err_laggtillpump_Click
DoCmd.GoToRecord , , acNewRec
Exit_laggtillpump_Click:
Exit Sub
Err_laggtillpump_Click:
MsgBox Err.Description
Resume Exit_laggtillpump_Click
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim varItem As Variant
Dim strSQL As String
'--- open the table
Set rst = CurrentDb.OpenRecordset("tblPumpsortEl")
'--- loop through all selected items in the list box
' adding data to the table
For Each varItem In Listruta43.ItemsSelected
rst.AddNew
rst!ProduktID = Me.id
rst!El = Listruta43(0, varItem)
rst.Update
Next varItem
'--- close the table
rst.Close
Set rst = Nothing
End Sub
But still it only puts data into tblPumpsort, nothing in to tblPumpsortEl:eek:
But i dont get it to work.
The tables looks like this:
tblPumpsort
id - counter (primary key and parent to table 2)
<more stuff>
tblPumpsortEl
id - counter (primary key)
ProduktID (child to id in tblPumpsort)
El
then i have some code to the addreccord button that looks like this:
Private Sub laggtillpump_Click()
On Error GoTo Err_laggtillpump_Click
DoCmd.GoToRecord , , acNewRec
Exit_laggtillpump_Click:
Exit Sub
Err_laggtillpump_Click:
MsgBox Err.Description
Resume Exit_laggtillpump_Click
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim varItem As Variant
Dim strSQL As String
'--- open the table
Set rst = CurrentDb.OpenRecordset("tblPumpsortEl")
'--- loop through all selected items in the list box
' adding data to the table
For Each varItem In Listruta43.ItemsSelected
rst.AddNew
rst!ProduktID = Me.id
rst!El = Listruta43(0, varItem)
rst.Update
Next varItem
'--- close the table
rst.Close
Set rst = Nothing
End Sub
But still it only puts data into tblPumpsort, nothing in to tblPumpsortEl:eek: