Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2017
    Posts
    2

    Unanswered: Access Form - Default Value UDF(). How can the UDF() know what control did the call

    Access 2010

    Hi

    For various text boxes on a form, I want to use a UDF() to return a string as the DefaultValue when the form opens. This UDF() is placed in the Properties dialog box.

    My question is, can the UDF() determine what control or text box is making the call? I know that Screen.ActiveControl returns a reference to the current control, but on startup, the control with the UDF() may not be the current control, but the DefaultValue section gets fired.


    Function DefaultVal() As String
    Dim ctl as Control
    Dim frm as Form
    Dim LookupName as string

    - this next line needs to be changed to reference the control with the code =DefaultVal() in DefaultValue property
    ctl = Screen.ActiveControl
    frm = ctl.Parent

    LookupName = frm.Name & "_" & ctl.Name
    DefaultVal = Lookup(LookupName) - some associated value based on the Form and Control
    End Function
    Last edited by smp999; 04-03-17 at 17:17.

  2. #2
    weejas is offline Grumpy old man (training)
    Join Date
    Sep 2006
    Location
    Surrey, UK
    Posts
    1,101
    Provided Answers: 17
    It would probably be easier to put the code in the form's Open event.
    10% of magic is knowing something that no-one else does. The rest is misdirection.
    Beers earned: 2

Posting Permissions

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