Results 1 to 4 of 4
  1. #1
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480

    If insert query fails, then

    Hello. I have a BE and FE database, whenever someone clicks a button on the front end... an insert query updates the back end... so we can track usage.. the back end is one table.. With this many people using the system, at an average of 1000 clicks daily... I am worried that if the table is being used by one user, then another user will not be able to make the update.. basically I want to add redundancy to this process... so this is what I have...



    -Original code, with zero redundancy...
    Code:
    Private Sub cmdAuthDatabase_Click()
    Call AuthData
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "qryFuncLog"
    DoCmd.SetWarnings True
    so this on click, runs the script, then does an insert query to the database....
    ---------------
    -What I want to do is.......
    Code:
    Private Sub cmdAuthDatabase_Click()
         Call AuthData
         DoCmd.SetWarnings False
    On Error GoTo Err:
         DoCmd.OpenQuery "qryFuncLog"
    Err:
      DoCmd.OpenQuery "qryFuncLog1"
         DoCmd.SetWarnings True
    SO if an error occours, it will point to another table and leave the insert there... HOWEVER while testing .... I hit a button on the front end... and the insert shows up in both tables.... as if there is always an error, or I did the Err: labeling wrong... any help is appreciated.

    Actually while writing this I think I will try this as well...

    Code:
    Private Sub cmdAuthDatabase_Click()
      On Error GoTo Err:
     Call AuthData
     DoCmd.SetWarnings False
     DoCmd.OpenQuery "qryFuncLog"
     DoCmd.SetWarnings True
    Err:
      DoCmd.SetWarnings False
      DoCmd.OpenQuery "qryFuncLog1"
      DoCmd.SetWarnings True
    End Sub
    Meh that did the same thing... made an entry into both tables... any idea?
    Last edited by redbull; 07-19-2012 at 01:35 PM.

  2. #2
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    qryfunclog code....
    Code:
    INSERT INTO tblFuncLog ( chrUser, chrFunction, dtmTimeStamp )
    SELECT Environ("username") AS Expr1, [screen].[activecontrol].[name] AS Expr3, Now() AS Expr2;
    qryfunclog1 code
    Code:
    INSERT INTO tblFuncLog1 ( chrUser, chrFunction, dtmTimeStamp )
    SELECT Environ("username") AS Expr1, [screen].[activecontrol].[name] AS Expr3, Now() AS Expr2;

  3. #3
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    Just thought about it... is there a way in the SQL statement to see if that table is busy... searching now, but I am so soft handed in SQL I know this is a long shot

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Code goes exactly where you tell it to go. In your case, you never told it to stop, so it just keeps executing lines until it gets to the end. You'd want to add

    Exit Sub

    in the appropriate spot. Here's how error handling is normally structured:

    http://www.baldyweb.com/ErrorTrap.htm

    Note the Exit Sub in the exit handler, to stop code from continuing into the error handler.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Access fails export query to XML
    By vinz in forum Access
    Replies: 1
    Last Post: 09-16-2014, 07:31 AM
  2. INSERT query: insert new data only
    By drh in forum Access
    Replies: 2
    Last Post: 04-04-2014, 05:31 PM
  3. Query works but VBA fails
    By dumbledown in forum Queries
    Replies: 11
    Last Post: 03-16-2012, 10:37 AM
  4. query fails
    By rjjhome in forum Queries
    Replies: 4
    Last Post: 03-15-2012, 05:19 PM
  5. Parameter Query Fails Occasionally
    By jp2access in forum Programming
    Replies: 0
    Last Post: 08-26-2009, 07:33 AM

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