Link to home
Start Free TrialLog in
Avatar of inimicaljords
inimicaljordsFlag for United States of America

asked on

Access 2007 Adding to db through listbox

Here's what I got going on.  I have an Access database with a table called TA.  I am making a form to add records to this table.  We have a scanner to scan serial numbers in to prevent typo's.  I came up with a form to use to support the scanner. Here is what we want to add

All serial numbers in list box will have the same PO #
(txtPObulk) I have a text box asking what the PO is
(lstSystemTag) I have a list box that we put all the serial numbers in.

I want to add all the serials numbers with the PO that was entered into the table TA

I was able to come up with a loop to cycle through the list, but I can't figure out how to add them to the table.  

I appreciate the help.
Private Sub Command31_Click()
Dim j As Long
With Me.lstSystemTag
    For j = 0 To .ListCount - 1
               'MsgBox Me.lstSystemTag.Column(0, j), vbOKOnly, "Item number:" & j + 1
    Next j
End With
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Boyd (HiTechCoach) Trimmell, Microsoft Access MVP 2010-2015
Boyd (HiTechCoach) Trimmell, Microsoft Access MVP 2010-2015
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of inimicaljords

ASKER

I don't quite understand what to put in your line of code.  I tried inputting field names but its not working.  I am not real sure on the syntax.  I am a bit rusty on this stuff.

only 2 fields I am changing is PO  and Systemtag, both are in a table called TA.  There are other fields in this table but this is all I want to input.

I am wanting the PO to be the same for all systemtag that are in the list.  So I only have to type the PO once and then I can scan the serial numbers into the list.
I got it to work with the following code.  Had to change it a little but figured it out.  Thanks!
CurrentDb.Execute "INSERT INTO TA (PO, SystemTag) VALUES ('" & Me.txtPObulk & "', '" & Me.lstSystemTag.Column(0, j) & "')"

Open in new window