SetWarnings Syntax

G

Guest

Hi, I am trying to do something I know is simple, but I'm just not getting it
right. I'd like to INSERT (create) a new record into my Transaction table and
insert the users UserID when they click a button. Can someone please tell me
what I'm doing wrong with this code? Thanks for any help!

Dim strSQL As String, strQuote As String, strUserID As String
strQuote = "'"
strUserID = Environ("username")

strSQL = "INSERT INTO [tblTransaction] (UserID) "

strSQL = strSQL & "VALUES (" & strQuote & strUserID & strQuote & ")"

DoCmd.SetWarnings (WarningsOff)
DoCmd.RunSQL strSQL
 
G

Guest

Hi.

The SetWarnings syntax requires a boolean value. Try the following in your
code:

DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True ' Turn warnings back on for subsequent code.

Make sure your error handling routine sets the warnings back to TRUE in case
an error occurs and the third line here doesn't execute. Probably better is
to use the following syntax:

CurrentDb( ).Execute strSQL, dbFailOnError

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)

- - -
When you see correct answers to your question posted in Microsoft's Online
Community, please sign in to the Community and mark these posts, so that all
may benefit by filtering on "Answered questions" and quickly finding the
right answers to similar questions. Remember that the best answers are often
given to those who have a history of rewarding the contributors who have
taken the time to answer questions correctly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top