Results 1 to 4 of 4
  1. #1
    asearle is offline Novice
    Windows XP Access 2003
    Join Date
    Jul 2010
    Posts
    24

    Errors but not warnings ?

    Hi Everyone,

    I have created a script (VBA program) which runs a chain of queries to do some simple processing. The queries will run either using currentdb.execute (with SQL) and/or docmd.openquery (with the SQL written to the appropriate query).

    As it is, I have opted for docmd.openquery because this gives me the option to switch warnings on (docmd.setwarnings true) in order to check the work of the queries.

    However, what I would really like to be able to do is to switch warnings off but tell the system to report errors if they occur.

    So my question is whether this is possible? Can I tell the queries to report errors but not warnings?

    That would be a great help to me.

    Many thanks,
    Alan Searle

  2. #2
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,172
    Hi,

    for trapping real errors you can of course use the normal error handling (on error goto ...) and the err object.
    If you want to know how many records are returned or affected by your query you can use the cmd object. An example of using the cmd object to perform an action query and store the number of records that were affected in the variable lngAffected:

    Code:
        Dim cmd As New ADODB.Command
        Dim cnn As ADODB.Connection
        Dim lngAffected As Long
        
        Set cnn = CurrentProject.Connection
        cmd.ActiveConnection = cnn
        cmd.CommandType = adCmdText
        cmd.CommandText = "Update tblTest set fldChangedOn = Now()"
        cmd.Execute lngAffected

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Try:
    currentdb.execute YourSQL, dbFailOnError

  4. #4
    asearle is offline Novice
    Windows XP Access 2003
    Join Date
    Jul 2010
    Posts
    24

    Exactly what I needed !!!

    Hi Guys,

    Many thanks: Both these recommendations will come in extremely handy.

    Many thanks,
    Alan Searle

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 10
    Last Post: 07-25-2011, 12:07 PM
  2. SQL that errors in VB
    By Wayne311 in forum Programming
    Replies: 3
    Last Post: 02-14-2011, 10:17 PM
  3. #Name? errors with textboxes
    By jasonbarnes in forum Forms
    Replies: 3
    Last Post: 12-16-2010, 09:51 AM
  4. Turn warnings off
    By Mclaren in forum Programming
    Replies: 6
    Last Post: 05-03-2010, 12:07 PM
  5. Set Warnings Off
    By NMJones in forum Access
    Replies: 2
    Last Post: 04-12-2010, 03:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums