Results 1 to 5 of 5
  1. #1
    Lounger
    Join Date
    Jul 2002
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ActiveForm in function called by On Current (Access 2000)

    I'm having a problem with a function that is called from the On Current event of several different forms. The purpose of the function is to record the ID number of each record, so that I have this value available to use in an audit trail program when I delete a record. This is the code:
    Function StoreIDs()
    Dim frm As Form
    Set frm = Screen.ActiveForm
    strPrevID = strCurrID
    strCurrID = frm!RecordID
    End Function

    This code works fine as long as I'm moving from record to record within a form. But when I close the form and reopen it, I get the following error message when the program reaches the ActiveForm statement: "Error 2475 You entered an expression that requires a form to be the active window."

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: ActiveForm in function called by On Current (Access 2000)

    The current event fires multiple times before the form is fully loaded and becomes visible. Until it *is* visible, Screen.ActiveForm will trigger an error because the form is not yet the ActiveForm. You could put a test into the Current event to only call the routine when the form is visible, like this:

    If Me.Visible = True Then
    StoreIDs
    End If
    Charlotte

  3. #3
    Lounger
    Join Date
    Jul 2002
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ActiveForm in function called by On Current (Access 2000)

    Thanks for the info about the current event. Your solution would work in an event procedure, but I can't use "Me" because my procedure is a function in a standard module. What would you suggest in this situation?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: ActiveForm in function called by On Current (Access 2000)

    The form (or report) that calls an event procedure is available in the CodeContextObject variable. Try this (I haven't really tested it):

    Function StoreIDs()
    If CodeContextObject.Visible = True Then
    strPrevID = strCurrID
    strCurrID = CodeContextObject!RecordID
    End If
    End Function

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: ActiveForm in function called by On Current (Access 2000)

    As long as the procedure is public, the code I posted will work. The Me.Visible code is inside the event procedure. You only call the function if the form that is calling it is visible. That's the whole point. Even though the current event fires repeatedly, it will only call the function if the form has become visible.
    Charlotte

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •