Solved

Access 2007 Adding to db through listbox

Posted on 2011-03-22
3
312 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:inimicaljords
  • 2
3 Comments
 
LVL 21

Accepted Solution

by:
Boyd (HiTechCoach) Trimmell, Microsoft Access MVP earned 500 total points
ID: 35193454
I normally handle this with an append query
Example:
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  
              CurrentDB.Execute "Insert into TA (field1, field2) Values( " & Me.Field1 & ", " & Me.lstSystemTag.Column(0, j)  & ")" 
    Next j  
End With  

End Sub

Open in new window


*** AIR CODE - Example for syntax
*** You will need to substiture the actual field names and form control names.

0
 
LVL 1

Author Comment

by:inimicaljords
ID: 35194767
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.
0
 
LVL 1

Author Comment

by:inimicaljords
ID: 35198081
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

0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now