Solved

Access 2007 Adding to db through listbox

Posted on 2011-03-22
3
338 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

739 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