Results 1 to 9 of 9
  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

    get NAME of the control (on a tab control) whose event fired a method

    is there an easy way of getting the NAME of the control (on a tab control) whose event fired a method



    the specific control I'm dealing with is on a tab control,
    in the code behind the event of that control i have:

    - me.ActiveControl.name

    which returns the name of the tab control; but (understandably) not the name of the control on it whose event fired the code

    with appreciation in advance,
    m.

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,389
    What event contains the code?
    My test for an AfterUpdate event works perfectly to debug.print the expected name of the control.
    Perhaps you could give more context.

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    That should work if the control is on the tab page (not on a form I think) and it has the focus. My simple test just proved that.
    If you cause a recalculation in a query in the event or requery the form the control will likely lose the focus. Might have to see your code at least, if not the db itself.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716

  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
    ...may be trying to do more than is warranted (and am in a bit of a dog chasing the other dog's tail scenario...);
    in the end, it may be better if i rethink the approach (?)

    on a tab page, I have multiple image controls, which can be double click'd to imitate a method
    the method behind the event is always the same (it opens a unrelated form), but with minor variants (different record source, different filter, different captions...)
    the variants are solely dependent on which image control was double_click'd

    b/c there is an existing table which holds the data which would influence the variants, ALONG WITH the name of the control,
    and i am already using code to lookup the variants by using the control name as the lookup criteria
    i thought that i could streamline the code behind the event to always be the same.

    like this:

    Code:
    Private Sub imgCNote_001_DblClick(Cancel As Integer)
    
        ' currently is:
        Call NoteEdit_DblClk("imgCNote_001")
    
        ' was hoping to change to be:
        Dim vCntrlName as string
        vCntrlName = me.TabCtl_Details.ActiveControl.name 'but not this; it results in an error...
    
        Call NoteEdit_DblClk(vCntrlName)
    
    End Sub

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Therein lies your problem, I'd say. AFAIK, an image control cannot accept the focus, thus it can't be "active". Instead of trying to pass the ActiveControl name property, pass the name of the image control to your function. Or pass the tag, which could be anything you want (and might actually make it easier/better).
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    BTW, in design view you can select all image controls and simultaneously assign the double click event to your function. You have to then individually include whatever data is needed for the function in that call. I don't think there's any way to make the assignment of that data universal in the event property sheet.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,398
    some options if you want to make the effort.

    1. use the mouse position to determine which image control is under the mouse

    2. use a web browser control to display the image - tho' you may have presentation issues

    however I think Micron's suggestion is the easiest way to go

    depends on how your form works, but in the form open event, you can assign a udf call to the double click event

    assuming your udf is called something like 'expandImage'

    include the control name

    function expandImage(controlname as string)

    and in your form open event something like

    Code:
    dim ctl as control
    
    for each ctl in me.controls
        if ctl.conttroltype=acImage then ctl.onDblClick="=expandImage(""" & ctl.name & """)
    next ctl

  9. #9
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Using a class module as an instance for each image at run time, you have the absolute control of each image in one code module.
    Create a class module (name it as clsMenuImage) and add this code:
    Code:
    Option Compare Database
    Option Explicit
    
    Private WithEvents mMenuImage As Image
    '
    Property Get MenuImage() As Image
        Set MenuImage = mMenuImage
    End Property
    
    Property Set MenuImage(value As Image)
        Set mMenuImage = value
    End Property
    
    Private Sub mMenuImage_Click()
        With mMenuImage
            MsgBox "Click " & .Name, , "Class clsMenuImage"
            .Parent.MenuClick .Name                             'Callback procedure of the form
        End With
    End Sub
    To use this class in [any] form with images, you need code [at least] like this:
    Code:
    Option Compare Database
    Option Explicit
    
    Private mColMenu As Collection                        'A collection for the clsMenuImage instances
    
    Function MenuImages() As Collection
        If mColMenu Is Nothing Then
            Dim clsImg As clsMenuImage
            Dim c As Control
            'Keep an instance of clsMenuImage for each image
            Set mColMenu = New Collection
            For Each c In Me.Controls
                If c.Name Like "imgMenu*" Then
                    c.OnClick = "[Event Procedure]"       'Enable the Click event
                    Set clsImg = New clsMenuImage         'Create a new instance
                    Set clsImg.MenuImage = c              'Set the MenuImage of this instance to this image
                    mColMenu.Add clsImg, c.Name           'Push it in collection
                End If
            Next c
        End If
        Set MenuImages = mColMenu
    End Function
    
    Private Sub Form_Load()
        MenuImages                                        'Initialize MenuImages collection
    End Sub
    
    Private Sub Form_Close()
        Set mColMenu = Nothing                            'Release the collection with all instances
    End Sub
    
    Public Sub MenuClick(strImage As String)
        'Callback procedure. Calling from clsMenuImage
        MsgBox "Click " & strImage, , "Form Menu"
    End Sub
    (apply the LIKE pattern to your needs)


    Take a look in attachment for a simple demonstration of the benefits of this option.
    Attached Files Attached Files

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

Similar Threads

  1. Replies: 6
    Last Post: 06-04-2018, 06:46 AM
  2. Replies: 7
    Last Post: 03-09-2018, 11:11 PM
  3. Replies: 14
    Last Post: 09-15-2017, 11:25 AM
  4. Replies: 4
    Last Post: 02-09-2013, 09:26 AM
  5. Common Dialog control / ShowOpen method
    By phuile in forum Forms
    Replies: 0
    Last Post: 04-10-2009, 12:16 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