Insert Into

G

Guest

Hi there,

I have a form based on tblGetApps with a list box (lstApps). The list box
will have several entries depending on what is chosen in a combo box. What I
need to do is have EmpId and Machine (all text fields) and everything in the
list box inserted into the tblGetApps table.

Private Sub cmdAdd_Click()
Dim db As Database

Set db = CurrentDb

db.Execute "INSERT INTO tblGetApps ( EMPLID, Machine, Apps ) & _
"Values (EmplId, Machine, lstApps)"

set db = Nothing

I get a syntax error and am not sure what is wrong with my query formation.

I have also tried:

Private Sub cmdAdd_Click()
Dim db As Database
' Dim rs As Recordset
Dim App as String

Set db = CurrentDb



' Set rs = db.OpenRecordset("tblGetApps")
' App = Me.lstApps.Value

'

'
' rs.AddNew
' rs![EmplId] = EmplId
' rs![Machine] = Machine
' rs![Apps] = App
' rs.Update
'


rs.Close: Set rs = Nothing
Set db = Nothing
End Sub

This works, sort of but will only insert the one item I have clicked on in
the list box, otherwise it just inserts the two items in the text boxes and
leaves Apps blank. What can I do to fix this so that everything from the
list box gets inserted?

Thanks,

All help immensely appreciated!
 
S

stefan hoffmann

hi,

Johnny said:
I have a form based on tblGetApps with a list box (lstApps). The list box
will have several entries depending on what is chosen in a combo box. What I
need to do is have EmpId and Machine (all text fields) and everything in the
list box inserted into the tblGetApps table. [..]
This works, sort of but will only insert the one item I have clicked on in
the list box, otherwise it just inserts the two items in the text boxes and
leaves Apps blank. What can I do to fix this so that everything from the
list box gets inserted?
Use the ItemsSelected property (see OH):

Sub BoundData()
Dim frm As Form, ctl As Control
Dim varItm As Variant

Set frm = Forms!Contacts
Set ctl = frm!Names
For Each varItm In ctl.ItemsSelected
Debug.Print ctl.ItemData(varItm)
Next varItm
End Sub



mfG
--> stefan <--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top