Results 1 to 9 of 9
  1. #1
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365

    Form Open Events and error trapping

    I'm trying to track down why a function is running 4 times before my main form opens.




    I understand the first event to fire is Form Open, so a Stop there should stop before anything else ?


    The function is called by the query that is the recordsource for the Main Forms subform.
    A Debug.print command in that Function is printing twice before the STOP command (first line of Main Form Open event).


    That doesn't seem possible if the first event is Form open, so something else is happening first?


    Any idea what ?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    If you call a function from a query, I expect it would be called for each record.

    Subforms load before main form.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    Thanks @June7 some things to take into account.
    The subform has up to 60 records and function is only firing twice.
    It may be called once for subfom loading, then again for the first record?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Okay, maybe not 60 times right off the bat.

    Possibly. Try Debug in each form's Load and Current events.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    Data related code should go in form load event IMO. I wouldn't be surprised that if on form opening, the query manages to retrieve 2 or so records before hitting the stop line. Code branching can cause certain events to repeat (e.g. because of Requery) or even get cancelled. You might want to try stepping through the code right at the form open event and watch the sequence of events. Or create a db copy, compact/repair and zip it and post it here so we can watch the sequence.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    As the subform loads first, and it's Open event fires first, a STOP there you'd expect to happen before anything else. But it doesn't.
    Code:
    Function ShowImage() As String
        Debug.Print "ShowImage" ': Stop
        On Error Resume Next
            Dim vPic As Variant
            If IsThisFormLoaded("frmMain") = True Then
                vPic = gFindFiles(CurrentProject.path & "\Images", Forms!frmMain!cboCode & ".bmp", False)
                If UBound(vPic) > 0 Then ShowImage = vPic(1)
            End If
        On Error GoTo 0
    End Function
    It's recordset query runs and debug prints it's function name twice. I'd just like to know why it does it twice. (Actually it used to do it 4 times but I seem to have changed that to 2 at the moment).
    To Step through events to see what's happening, where might a Stop go to be the very first thing Access does ? Or is this not possible, Access is doing stuff before any procedure starts?

  7. #7
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    How big is this database? Can you post a copy with a subset of records that show this problem?

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Is this really a problem?

    I've never used Stop for debugging. Just breakpoints, Debug.Print, and stepping.

    So I just tested a Stop in form Open event and used that form as subform. The Stop works.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    @June, did you call a function from your subforms recordsource.?
    If yes, how many times did it run before reaching Form Open event?
    I've never used breakpoints, only Stop.
    You're probably right, this isn't a problem but knowing how to stop anything running when a For opens (then seeing what happens next) could be useful.
    @orange - still attempting subset example.

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

Similar Threads

  1. Error trapping ms access
    By niktsol1978 in forum Access
    Replies: 12
    Last Post: 11-23-2019, 01:56 AM
  2. error trapping on a subform
    By dgmdvm in forum Forms
    Replies: 4
    Last Post: 08-24-2018, 02:52 PM
  3. Append query error trapping
    By tpcervelo in forum Programming
    Replies: 4
    Last Post: 12-22-2011, 10:57 AM
  4. Proper Error Trapping
    By SemiAuto40 in forum Programming
    Replies: 6
    Last Post: 08-11-2011, 10:22 AM
  5. Form and Subform error trapping
    By usmcgrunt in forum Forms
    Replies: 8
    Last Post: 09-12-2010, 11:54 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