Insert Into still not working

G

Guest

Hi there,

I have a form with a list box (lstApps). What I
need to do is have EmpId and Machine (2 text boxes) and everything in the
list box inserted into the tblGetApps table with Empid and Machine being
repeated in each record.

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!
 
B

Brian Bastl

Your values to be inserted need to be concatenated to your SQL.

On the Assumption that EmplId is numeric, Machine is text, and lstApps is
numeric, your code would look like:

Dim db As DatabaseSet db = CurrentDb

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

HTH,
Brian

Johnny Bright said:
Hi there,

I have a form with a list box (lstApps). What I
need to do is have EmpId and Machine (2 text boxes) and everything in the
list box inserted into the tblGetApps table with Empid and Machine being
repeated in each record.

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!
 
B

Brian Bastl

Sorry, just noticed that I left out the trailing ampersand. Should be: '" &
Machine & "'

Brian


Brian Bastl said:
Your values to be inserted need to be concatenated to your SQL.

On the Assumption that EmplId is numeric, Machine is text, and lstApps is
numeric, your code would look like:

Dim db As DatabaseSet db = CurrentDb

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

HTH,
Brian

Johnny Bright said:
Hi there,

I have a form with a list box (lstApps). What I
need to do is have EmpId and Machine (2 text boxes) and everything in the
list box inserted into the tblGetApps table with Empid and Machine being
repeated in each record.

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!
 

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

Similar Threads

Insert Into 1
Multi Select List Box in Access 0
NotInList not firing ? 1
forms Coding 6
Getting message when modifying 2
NotInList Warning 4
get the previous data and make the chages 1
Not in list not working 1

Top