Hello all,
I have a multiselect list box where I want to select multiple records, select a single value from a combo box in another place on the form, and then create multiple new records in a join table, like so:
Table 1 Table 2
(source for List Box) (source for combo box)
A 1
B 2
C
D
So therefore, if I selected A,B, and C from the list box, and then 1 from the combo box, my join table would look like:
Table 3 (Join Table)
Field 1 Field 2
A 1
B 1
C 1
How can I code for this? I found some code in a book that I think is applicable, but I'm fairly new at VBA so I can't be sure. It's currently stopping on the rst.Open line, saying that it can't find the field that I want it to. Can anyone help me? Thanks!!!!!
Private Sub Specification_Req_Click()
Dim rst As New ADODB.Recordset
Dim cnn As ADODB.Connection
Dim msg As String, varNumber As Variant
Set cnn = CurrentProject.Connection
rst.Index = "Primary Key"
rst.Open [Specification Source], adOpenStatic, adLockOptimistic, adCmdTableDirect
For Each varNumber In [Specification Source].ItemsSelected
rst.Seek [Specification Source].ItemData(varNumber), adSeekFirstEQ
rst!Specification_Req = cboNew
rst.Update
Next
cboCurrent = cboNew
cboNew = Null
[SpecificationSource].Requery
End Sub
I have a multiselect list box where I want to select multiple records, select a single value from a combo box in another place on the form, and then create multiple new records in a join table, like so:
Table 1 Table 2
(source for List Box) (source for combo box)
A 1
B 2
C
D
So therefore, if I selected A,B, and C from the list box, and then 1 from the combo box, my join table would look like:
Table 3 (Join Table)
Field 1 Field 2
A 1
B 1
C 1
How can I code for this? I found some code in a book that I think is applicable, but I'm fairly new at VBA so I can't be sure. It's currently stopping on the rst.Open line, saying that it can't find the field that I want it to. Can anyone help me? Thanks!!!!!
Private Sub Specification_Req_Click()
Dim rst As New ADODB.Recordset
Dim cnn As ADODB.Connection
Dim msg As String, varNumber As Variant
Set cnn = CurrentProject.Connection
rst.Index = "Primary Key"
rst.Open [Specification Source], adOpenStatic, adLockOptimistic, adCmdTableDirect
For Each varNumber In [Specification Source].ItemsSelected
rst.Seek [Specification Source].ItemData(varNumber), adSeekFirstEQ
rst!Specification_Req = cboNew
rst.Update
Next
cboCurrent = cboNew
cboNew = Null
[SpecificationSource].Requery
End Sub