By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,780 Members | 1,118 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,780 IT Pros & Developers. It's quick & easy.

Problem in inserting a row to MS-Access Table

P: 2
Hi Everyone,

I am trying to insert a row into MS-Access table. The table contains the details of error (number and description) occured in the whole script. The query written for inserting a row is as follows.

strQuery = "Insert into ErrorLog values('& Err.Number & ",' " & Err.Description & " ')"

The problem is the Error description is like "The directory doesn't exists", in which a single quote is present (doesn't). Because of that the row is not getting inserted.

So can u please suggest mw how to overcome this issue.

Thanks in Advance
Priya ramanan
Dec 17 '07 #1
Share this Question
Share on Google+
5 Replies

Expert 100+
P: 1,445
Hi ,

Try to use Replace Function :
Something like this :

strQuery = "Insert into ErrorLog values(" & Err.Number & ",' " & Replace(Err.Description, "'", "") & " ')"

Dec 17 '07 #2

P: 2
Thanks Veena. Its working fine.

But to know more about the problem, i am asking you this.
Is there any other solution to solve this issue.

If so just let me know.

Thanks Again

Priya ramanan
Dec 17 '07 #3

Expert 100+
P: 1,445

You can Open a Dynamic RecordSet and add, using "AddNew" method, Instead of using an "Insert" Statment.

Also, you can use Escape Characters..

Dec 17 '07 #4

Expert 5K+
P: 8,434
There's also an article in the Access "HowTo's" on TheScripts which discusses the various issues around single and double quotes.
Dec 17 '07 #5

P: 41
I found this article to be very helpful in overcoming issues like this.

Always Use Parameters, even if you don't use Stored Procedures

Hope this was helpful,
Dec 19 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.