Can anyone tell me what's wrong with this VBA?

B

Bonnie

strSQL = "INSERT INTO TrackDocs (DateReceived) " & "VALUES(" & Format(Now(),
"mm/dd/yyyy") & ")"

CurrentDb.Execute strSQL, dbFailOnError


Thanks in advance.

Bonnie
 
A

Allen Browne

If DateReceived is a Date/Time field, lose the Format().
Now() is already a date/time value, so just assign it to the field.
 
B

Bonnie

Thanks that fixed that problem.

Here's another question if you wouldn't mind - what's wrong with this (I am
inserting into two fields now):

strSQL = "INSERT INTO TrackDocs (DocumentID), (DateReceived) " & "VALUES(" &
Chr$(34) & strFile & Chr$(34) & Now() & Chr$(34) & Chr$(34) & ")"
CurrentDb.Execute strSQL, dbFailOnError

Thanks!
 
D

Douglas J. Steele

strSQL = "INSERT INTO TrackDocs (DocumentID, DateReceived) " & "VALUES(" &
Chr$(34) & strFile & Chr$(34) & ", " & Now() & ")"
CurrentDb.Execute strSQL, dbFailOnError
 
B

Bonnie

Thanks for responding.

I'm still getting an error. It says the syntax is wrong: missing operator
and it relates to the date field?

Any help appreciated.

Bonnie
 
B

Bonnie

Sorry Doug - I got it. I added the "#" around the date and it's good.
Thanks for your help.

Bonnie
 
J

John W. Vinson

strSQL = "INSERT INTO TrackDocs (DocumentID, DateReceived) " & "VALUES(" &
Chr$(34) & strFile & Chr$(34) & ", " & Now() & ")"
CurrentDb.Execute strSQL, dbFailOnError

Shouldn't that have # delimiters around the Now()?

strSQL = "INSERT INTO TrackDocs (DocumentID, DateReceived) " & "VALUES(" &
Chr$(34) & strFile & Chr$(34) & ", #" & Now() & "#)"
CurrentDb.Execute strSQL, dbFailOnError
 
D

Douglas J. Steele

John W. Vinson said:
Shouldn't that have # delimiters around the Now()?

strSQL = "INSERT INTO TrackDocs (DocumentID, DateReceived) " & "VALUES(" &
Chr$(34) & strFile & Chr$(34) & ", #" & Now() & "#)"
CurrentDb.Execute strSQL, dbFailOnError

I was going by what Allen said, but I blew it. With Now being outside of the
quotes, yes, you need the delimiters, However, I believe

strSQL = "INSERT INTO TrackDocs (DocumentID, DateReceived) " & "VALUES(" &
Chr$(34) & strFile & Chr$(34) & ", Now())"

will work.
 
Top