Results 1 to 7 of 7
  1. #1
    Budatlitho is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2016
    Posts
    36

    Passing target value to public function

    Hello!

    Here is JavaScript from Acrobat:
    Code:
    function bg1(){//on Focus, make field background color light yellow
        event.target.fillColor = ["RGB", 1,1,.85];
    }
    //
    function bg2(){//on Blur, make field background transparent
        event.target.fillColor = color.transparent;
    }
    //
    I can call these functions in the Acrobat form field's property actions for onFocus and onBlur to change the fill color.

    I have this public function in Access:
    Code:
    Public Function SetFillColor()
    Dim lngRed As Long
    lngRed = RGB(255, 0, 0)
    EventTarget.ForeColor = lngRed
    End Function

    I would like to call this from a control's On Got Focus property by passing the current control's "Target" value...
    Obviously, this doesn't work... EventTarget is seen as an undefined variable.

    Probably easy, but have spent much time with no success. :-(

    THANKS in advance....

    Somewhat-dangerous-programmer Bud

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    Pass in the control as an object, call it eventobject in the function declaration, else change names to suit.
    However, if that is all it does, may as well code it in the calling code?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    Budatlitho is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2016
    Posts
    36
    Quote Originally Posted by Welshgasman View Post
    Pass in the control as an object, call it eventobject in the function declaration, else change names to suit.
    However, if that is all it does, may as well code it in the calling code?
    How do I code it in the calling code?

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    Quote Originally Posted by Budatlitho View Post
    How do I code it in the calling code?
    Use activecontrol as mentioned

    Call SetFillColor(Me.ActiveControl)

    NB: Forecolor does not set FILLCOLOR, backcolor does that.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Quote Originally Posted by Budatlitho View Post
    How do I code it in the calling code?
    If you have to deal with specific count of controls,

    1. Paste the functions below in a module:

    Code:
    Function GotFocus()
        Screen.ActiveControl.BackColor = vbRed
    End Function
    
    Function LostFocus()
        Screen.ActiveControl.BackColor = vbWhite
    End Function
    2. Select all the controls that you want and in properties sheet, in tab "Event", apply each function to the corresponding event as seems below:

    Click image for larger version. 

Name:	GotLostFocus.JPG 
Views:	17 
Size:	15.9 KB 
ID:	47810

    If you have to deal with unknown count of controls at run-time, you have to code the events of the controls within a class module.

    Cheers,
    John

  7. #7
    Budatlitho is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2016
    Posts
    36
    Great, understandable solution!

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

Similar Threads

  1. Public Function
    By sparker75 in forum Programming
    Replies: 14
    Last Post: 11-14-2018, 10:21 AM
  2. Replies: 15
    Last Post: 10-17-2018, 09:26 PM
  3. Public Function
    By ShostyFan in forum Programming
    Replies: 3
    Last Post: 09-30-2017, 09:58 AM
  4. Passing arguments to a public sub
    By EonsTimE in forum Programming
    Replies: 4
    Last Post: 04-05-2016, 03:29 PM
  5. Replies: 11
    Last Post: 05-17-2013, 06:10 AM

Tags for this Thread

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