Results 1 to 12 of 12
  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    Pass a control into a public sub and have it's event fire

    I have in the code

    If Not IsMissing(FireEvent) Then


    Call FireEvent_AfterUpdate
    End If

    baisically I am passing me.swaplist

    I get an error when I pass me.swaplist as FireEvent

    Can this be done?

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Can you show us more code where this resides? Not enough info or context for me.

  3. #3
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Code:
    Public Sub tagVisibility(DateFrom As Variant, DateUntil As Variant, TagName As String, FormImport As Form, Optional FireEvent As Variant)
    Dim ctl As Control
    
    
    If IsNull(DateFrom) Or IsNull(DateUntil) Then
            Debug.Print "Got to Here"
            For Each ctl In FormImport.Controls
                Select Case ctl.ControlType
                Case acComboBox, acTextBox, acCommandButton, acLabel, acListBox, acSubform
                    If ctl.Tag = TagName Then
                    ctl.Visible = False
                    Else
                    ctl.Visible = True
                    End If
                   
                End Select
             Next ctl
             
        Else
        
            For Each ctl In FormImport.Controls
                Select Case ctl.ControlType
                Case acComboBox, acTextBox, acCommandButton, acLabel, acListBox, acSubform
                    If ctl.Tag = TagName Then
                    ctl.Visible = True
                    End If
                   
                    If Not IsMissing(FireEvent) Then
                   Call FireEvent_AfterUpdate
                    End If
                    
                End Select
             Next ctl
             
        End If
        
    End Sub
    Note the after update is a control afterupdate on the form and is a private sub

  4. #4
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    calling the function

    Call tagVisibility(Me.DateFrom_Box, Me.DateUntil_Box, "Vanish", Me.Form, Me.SwapList)

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Not certain, but I think you have to reference the form on which control event is located????

    Where is the FireEvent_AfterUpdate located? Me. ??

  6. #6
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Yeah, It's on the end me.swaplist

    I tried passing as control too

    I've tried FormImport.refresh too

    the afterupdate event has to fire because it gives me a count in a label caption after it has been updated. So I'd like it to have it's afterupdate event fired.

  7. #7
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Call tagVisibility(Me.DateFrom_Box, Me.DateUntil_Box, "Vanish", Me.Form, Me.SwapList)

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Try (guessing)
    Call tagVisibility(Me.DateFrom_Box, Me.DateUntil_Box, "Vanish", Me, Me.SwapList)

  9. #9
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by orange View Post
    Try (guessing)
    Call tagVisibility(Me.DateFrom_Box, Me.DateUntil_Box, "Vanish", Me, Me.SwapList)


    using
    Call FormImport.FireEvent_AfterUpdate

    Makes no difference - same object error

  10. #10
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    If you know how to force the combo box to select something that could help fire the after update...

    I've tried in the select case too

    case vbComboBox

    ctl.requery

    but no luck

  11. #11
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    I found calling a control event only works on the forms vba and not in a module.....

  12. #12
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    See this link , seems others have done this. (found via Google)

    Form_frmName.PublicSubName(anyVars)

    Here is info from a recent email on another group
    I have a command button on one form that opens a second form. On the second
    form, I use a click event to enable and disable other controls based on the
    value in the clicked event.

    I'm also passing a value to the second form and using that to filter the
    form's Recordset -- so the control that determines the disabling and
    enabling has a selected value. I need to force that click to enable and
    disable the other controls....
    When I explicitly name the form in the Call statement, I get an error --

    Call Forms![Enter Disposition Details]!lstDispositionDetailsID_Click()
    Here was a response, but I haven't heard success/failure yet..

    Try:

    Call Forms("Enter Disposition Details "). lstDispositionDetailsID_Click

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

Similar Threads

  1. Pass DAO.Recordset into public function
    By Ruegen in forum Programming
    Replies: 1
    Last Post: 07-07-2014, 12:31 AM
  2. Replies: 9
    Last Post: 03-18-2014, 07:02 PM
  3. Replies: 5
    Last Post: 12-03-2013, 01:25 PM
  4. Replies: 3
    Last Post: 05-07-2012, 12:17 PM
  5. Trying to fire event on record change
    By danielhowden in forum Forms
    Replies: 3
    Last Post: 05-13-2011, 06:30 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