Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT INTO Query Problem 1

Status
Not open for further replies.

rookery

Programmer
Apr 4, 2002
384
0
0
GB
Anyone figure whats wrong with the following code:

Set dbs = CurrentDb
Set MyRs = dbs.OpenRecordset("tblMailMerge", dbOpenDynaset)
Do Until MyRs.EOF
With MyRs
.MoveFirst
intCust = ![CustID]
dbs.Execute "INSERT INTO ClientNotes (CustID, Date, NoteText) VALUES (10, 26/07/2002, 'MailMerge Letter Sent!'"
.MoveNext
End With
Loop

I'm getting a "Syntax Error in INSERT INTO query" error, yet the table and field names are all correct.
Ideas?
 
Is your post an exact copy of the SQL? If so, there is a ) missing from the end of the query. Have fun! :eek:)

Alex Middleton
 
Thanks for your replies people. Alex, my mistake, it wasn't an exact post - I must have missed the last bracket off during the COPY. I tried your suggestion Svet, but no joy.
If at first you dont succeed....
 
Yes Flan it is. Should it read:

VALUES (" & 10 & ", 26/07/2002, 'MailMerge Letter Sent!'")


 
All this sun must be going to my head! My apologies - I've just double checked and it is an AutoNumber field.
 
Blimey I really have got sunstroke! Believe me this time when I say it is a Number field.
 
Hi Rookery

You can't have a field called Date. At least, you can, but it won't work in SQL. There's a reason for this. I've just forgotten it.

Changing your fieldname, and your code works fine.

HTH

Ben
 
You're a diamond Ben. Thanks alot. Just out of interest though, my code seems to get stuck in a never-ending loop. I've sorted out a workaround but would be interested to know why this is happening for future ref.

Cheers again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top