Patrick O'Dea
asked on
One line of VBA ... frustrating , quotes, single and double etc
This nex t line below works fine
CurrentDb.Execute "insert into [tblAuditlog] (Auditstr) values ( ' " & AuditDetails & " ')"
However, I also have a field AuditDate in tblAuditlog and I want to put now() into this field.
How do I change my VBA to add this date.
... tried multiple things so far but failed..
CurrentDb.Execute "insert into [tblAuditlog] (Auditstr) values ( ' " & AuditDetails & " ')"
However, I also have a field AuditDate in tblAuditlog and I want to put now() into this field.
How do I change my VBA to add this date.
... tried multiple things so far but failed..
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for you help.
I have lots of solutions.
Before I close the query...
Can anybody refer me to a site that explains the the usage of quotes and single quotes when inserting into a table.
I understand most of this area but seem to struggle (and guess) everytime.
I have lots of solutions.
Before I close the query...
Can anybody refer me to a site that explains the the usage of quotes and single quotes when inserting into a table.
I understand most of this area but seem to struggle (and guess) everytime.
SQL uses single quotes to denote strings.
VBA uses double qotes to denote strings
So a VBA string that contains an SQL statement will use double-quotes for the vb part but single quotes internally.
e.g.
dim sql as string
sql = " INSERT INTO MYTABLE (FIRST_NAME) VALUES ( 'paul' ) "
VBA uses double qotes to denote strings
So a VBA string that contains an SQL statement will use double-quotes for the vb part but single quotes internally.
e.g.
dim sql as string
sql = " INSERT INTO MYTABLE (FIRST_NAME) VALUES ( 'paul' ) "
Access accepts both quotes and double quotes. SQL only accepts quotes. Quotes force the value to be considered as string. Usually, when you use quotes with dates, it gets converted automatically (same as numbers when inserting the string '5' into a numeric field, for example).
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks all
CurrentDb.Execute "insert into [tblAuditlog] (AuditDate) values ( ' " & date() & " ')"
or
CurrentDb.Execute "insert into [tblAuditlog] (AuditDate) values (date())"
Chris