Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / March 2005

Tip: Looking for answers? Try searching our database.

SetWarnings Syntax

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Find a Ritz guy - 05 Mar 2005 15:27 GMT
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
'69 Camaro - 05 Mar 2005 15:45 GMT
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.

> 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
[quoted text clipped - 11 lines]
>         DoCmd.SetWarnings (WarningsOff)
>         DoCmd.RunSQL strSQL
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.