Results 1 to 5 of 5
  1. #1
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496

    "0" error on form open

    i have a very simple unbound form with 2 unbound controls
    the only code behind it is below(On Open) (and a 2nd event On Timer...)
    yet when the form opens, it executes the code and then responds with a "0" error (and no description)

    am i missing something?
    maybe i simply need to have an "exit sub" immediately before "on Error"?
    (could it be that simple?)

    as always, with thanks in advance,
    m.



    Code:
    Private Sub Form_Open(Cancel As Integer)
    On Error GoTo Err_Form_Open
        ' Set Count Down variable to false
        ' on the initial opening of the form.
        strMDb_shutdown_Folder = DLookup("[MDb_shutdown_Folder]", "tblMDb_Shutdown")
        strMDb_shutdown_FileName = strMDb_shutdown_Folder & "/" & DLookup("[MDb_shutdown_Filename]", "tblMDb_Shutdown")
    '    MsgBox (strMDb_shutdown_Folder & vbCrLf & strMDb_shutdown_FileName)
        blnCountDown = False
        Me.txtSetFocus.SetFocus
    Err_Form_Open:
        If Err.Number = 3044 Then
            gsMsgText = "The MDb file needs to be relinked...."
            gsMsgTitle = "MDb LINK ERROR"
            gsMsgResponse = MsgBox(gsMsgText, vbExclamation + vbOKOnly, gsMsgTitle)
        Else
           MsgBox Err.Number & " - " & Err.Description
        End If
    End Sub

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Easy to figure out if you step through the code. Put a break point on the line beginning with Private then open the form and step through (F8?)
    I could just tell you what the fix is but I get the feeling that you need to learn how to watch code execution line by line. It's invaluable when trouble shooting.
    Hint: you need an Exit Sub line somewhere.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    thnx
    ...actually had been stepping; but never realized (occasionally amazed at the simple things i still do not realize =:- )

    if you don't "exit Sub"
    ...of course

    Q:
    as a matter of good practice, should i always have an "exit sub" immediately prior any error trapping code?

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    You'd use Exit Sub anywhere you'd want to prevent other code from running, but most definitely before an error handler. If there are any objects that should be 'destroyed' (anything that was "Set") my approach is like:

    Code:
    Dim variables
    
    On Error GoTo errHandler
    Set objects
    
    more code
    
    exitHere:
    On Error Resume Next
    rs.Close (rs = recordset) << some say that setting it to Nothing is good enough.
    Set rs = Nothing
    Set db = Nothing
    Exit Sub
    
    errHandler:
    error handling code
    Resume exitHere
    IMO this style is especially important if you have to turn off warnings. If warnings are turned off and code is allowed to simply stop, they can remain off until the db is re-opened.
    Last edited by Micron; 07-12-2021 at 09:12 PM. Reason: code correction
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    ACES (thnx yet again)

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

Similar Threads

  1. Replies: 6
    Last Post: 10-09-2019, 06:57 PM
  2. Replies: 2
    Last Post: 02-06-2019, 01:24 PM
  3. Replies: 3
    Last Post: 07-12-2017, 04:29 PM
  4. Replies: 1
    Last Post: 09-07-2015, 08:00 AM
  5. Replies: 3
    Last Post: 02-06-2015, 03:22 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