insert query on recordset error?

B

bob

Can some one tell me what I am doing wrong here? creating
a clone of a form which is getting half the values from a
table and the other half are entered by the user on the
form. This recordset is then suppose to insert the records
in to the table.

The error is a syntax error wnd is the last line in the
insert query code.

Private Sub Command46_Click()

Dim strsql As String
Dim rs As DAO.Recordset
Dim db As DAO.Database ' for insert queries

Set db = CurrentDb
Set rs = Me.RecordsetClone

With rs

If .RecordCount <> 0 Then .MoveFirst

Do Until .EOF

'try entering only one value

strsql = _
"insert into tblattendance" & _
"(tblattendance.programcode)"
"VALUES("!progcode & ") ' error here

db.Execute strsql, dbFailOnError

.MoveNext
Loop
End With

Set rs = Nothing
Set db = Nothing
End Sub
 
D

-D-

Hi There,

try using the ambersand (&) just before !progcode.

Also, after "(tblattendance.programcode)", there should be
continuation to the next line, ie. "& _" just like you
have after your first line. Also, a double quote at the
very end. So it would all look like this:

strsql = _
"insert into tblattendance" & _
"(tblattendance.programcode)" & _
"VALUES(" & !progcode & ")"

If that doesn't work, try "VALUES(" & .Fields
("progcode").Value & ")"

Hopefully this will help out.
good luck
 

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


Top