Results 1 to 6 of 6
  1. #1
    Middlemarch is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2015
    Posts
    479

    On Click event - apply to all text box controls


    Can I do this - so all text box box controls could send their name to a shared UDF?

    Thanks.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Yes. Send any value you want. Call the function from Click or AfterUpdate event property.

    Example of calling a function from a button Click event:

    =HandleButtonClick(1)
    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 XP Access 2003
    Join Date
    Mar 2015
    Posts
    479
    Sorry i meant one function for all, not duplicated for each control.
    I have found something -

    Code:
    Private Sub Form_Load()
    Dim ctl As Control
    For Each ctl In Me
        If ctl.ControlType = acTextBox Then
            ctl.OnDblClick = "=doubleclick([" & ctl.Name & "])"
        End If
    Next ctl
    End Sub
    
    Function doubleClick(x) As String
        Debug.print x
    End Function
    However I'm stumped as although I'm passing the control Name, what arrives is the control value.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    If you want doubleClick() to output the control name as a literal string, remove the [] and use apostrophes instead. The brackets define an object reference which is why you get the value from current record when you dblClick the textbox.

    Or if doubleClick is behind the form, leave the brackets and change code to:

    Debug.Print Me.Controls(x.Name).Name

    Or in any module:

    Debug.Print Forms(CurrentObjectName).Controls(x.Name).Name

    What do you eventually really want to happen when textbox is double clicked?

    My example sets the event property in design. Why are you setting property during runtime?
    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
    Middlemarch is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2015
    Posts
    479
    Thanks for the tip about apostrophes !

    >Why are you setting property during runtime?

    There's a lot of text boxes and this one procedure works for all of them.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Yes, a lot of textboxes but in design set it once and done.

    Did some edits on my previous post.
    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.

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

Similar Threads

  1. Replies: 2
    Last Post: 10-09-2016, 05:41 PM
  2. Need help with click Event
    By DXXPublic in forum Programming
    Replies: 3
    Last Post: 09-23-2015, 06:55 PM
  3. Replies: 13
    Last Post: 09-10-2015, 03:37 PM
  4. Replies: 7
    Last Post: 08-22-2013, 05:24 PM
  5. Replies: 3
    Last Post: 08-02-2013, 12:18 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