Hi, I need help with populating a subform from data in a listbox which contain data from a querry: q_sum_A
Hereis data example from q_sum_A:
Here is my form look like:
The main form contains: ListboxA (Data from q_sum_A querry), cmd_add button and a sub form: SubformA
I need some help working with VBA with cmd_add button.
I have tried this but it not working:
*LinkID is a field that link main form and a subform
Anyone have an idea? Thank you in advance
Hereis data example from q_sum_A:
CODE (Short text) | VALUE (Number) | NOTE (Long text) |
A 00 01 000 | 27.18 | RC Footing |
A 02 00 000 | 0.88 | RC Slab |
A 04 01 001 | 770 | RC Collumn |
Here is my form look like:
The main form contains: ListboxA (Data from q_sum_A querry), cmd_add button and a sub form: SubformA
I need some help working with VBA with cmd_add button.
I have tried this but it not working:
Code:
Dim ctrl As Control
Dim strsql As String
Dim varitem As Variant
Set ctrl = Me.ListboxA
If ctrl.ItemsSelected.Count > 0 Then
For Each varitem In ctrl.ItemsSelected
strsql = "INSERT INTO t_cost_fix(LinkID, CODE, VALUE, NOTE)" & _
"VALUES(" & Me.LinkID* & "," & ctrl.ItemData(varitem) & ")"
CurrentDb.Execute strsql, dbFailOnError
Next varitem
Else: MsgBox "Please select an item in the listbox", vbInformation, "Information"
End If
Me.SubformA.Requery
*LinkID is a field that link main form and a subform
Anyone have an idea? Thank you in advance