Solved

CurrentDb.Execute "insert into [tblAuditlog]  ,,,,,, Quotes again

Posted on 2011-03-21
6
301 Views
Last Modified: 2012-05-11
Hi See code below.  

I have added a new field "AuditCategory" onto my tblAuditlog.
My VBA insert to this table previously worked but now I want to add this new field to the insert statement..

How Do I add the variable "strAuditCategory" into my insert statement - (it should be written to the field name AuditCategory obviously).  

I have tried a few combinations but have got confused by the quotes, commas etc.  (This confusion is a speciality of mine!)
BEFORE:
CurrentDb.Execute "insert into [tblAuditlog] (Auditstr,auditDate) values ( '" & AuditDetails & "',#" & Now() & " #)"

Open in new window

0
Comment
Question by:Patrick O'Dea
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 9

Accepted Solution

by:
McOz earned 125 total points
ID: 35180730
Try this:
BEFORE: 
CurrentDb.Execute "insert into [tblAuditlog] (Auditstr,auditDate,AuditCategory) values ( '" & AuditDetails & "',#" & Now() & " #,'" & strAuditCategory & "')"

Open in new window

0
 
LVL 4

Assisted Solution

by:joeyw
joeyw earned 125 total points
ID: 35180744
I've struggled with the quotes thing on sql fields in the past.  The easiest thing that I have is to use the chr statement

values (chr(34) & auditdetails & chr(34) ....
0
 

Author Comment

by:Patrick O'Dea
ID: 35180823
Thanks joeyw ,

McOz,  I probably should know but what does the # do.

(You code works perfectly by the way).
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 250 total points
ID: 35181015
21Dewsbury,
if you are just taking notes, you should know this by now as this was posted sometime ago in one of your questions..

for number data type you use  " & myNumbervariable  & "
for text                                '" & mytextVariable  & "'
                 (exploded view )   ' " & myTextvariable & " '

for Date  Data Type               #" & dateVariable & "#
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 250 total points
ID: 35181048
in addition.. if string have single quotes like  varName= O'Brien
you use

" & chr(34) & varName & chr(34) & "

0
 

Author Closing Comment

by:Patrick O'Dea
ID: 35181108
Thanks all,

Incidentally, capricorn1, I did actually refer to the query of a few weeks ago.

However, I misinterpreted the solution posted by Mcoz and thought that there was additional #'s due to the additional string.

On second reading the # is not relevant to my query.

Thanks again,
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question