Results 1 to 5 of 5
  1. #1
    beesee is offline Novice
    Windows 7 64bit Access 2002
    Join Date
    Jan 2016
    Location
    Vancouver, BC
    Posts
    15

    Question Getting the Control Source Name of the Active Control vs Form Name of the control

    I have control source on a form [ProjectDescription] and the Form Name is also ProjectDescription.

    Public FilterCtl As String has been previously declared.

    On my Form I enter into a the control which triggers this:



    Code:
    Private Sub ProjectDescription_Enter()
        Me.ActiveControl.SetFocus
        FilterCtl = Screen.ActiveControl.Name
        
    End Sub
    Then I move to a text box and enter key words and press a control button:

    Code:
    Private Sub cmdFilterKey_Click()
    
    Me.Filter = FilterCtl & " Like " & Chr(34) & "*" & Me.TextKeyWords & "*" & Chr(34)
       Me.FilterOn = True
       Me.Requery
       
    End Sub
    This all works fine.

    My question is the use of "Screen.ActiveControl.Name". This gets the form name of the control. It only works in Me.Filter if that name is the same as the actual control source itself. How do I get it to work if the name of the control source field name is different than the control name. For instance the form name of [ProjectDescription] is ProjDesc?

    I can't figure out what to use in place of FilterCtl = Screen.ActiveControl.Name

    Thanks in advance.
    Last edited by beesee; 02-16-2016 at 01:48 PM. Reason: Wrapped code

  2. #2
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    656
    Does this function always running based on the same control for the filter? Would the Kludge of [Forms]![yourformname].form!ProjectDescription or something of that nature work?

  3. #3
    beesee is offline Novice
    Windows 7 64bit Access 2002
    Join Date
    Jan 2016
    Location
    Vancouver, BC
    Posts
    15
    Thanks for the input Perceptus. However if I use [Forms]![yourformname].form!ProjectDescription it returns the actual text contents of the field. I need to return the actual [Control Source]

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    2,915
    If you want the ControlSource, ask the Access Gnomes for it:

    FilterCtl = Screen.ActiveControl.ControlSource

    Or have I misunderstood your question?

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    beesee is offline Novice
    Windows 7 64bit Access 2002
    Join Date
    Jan 2016
    Location
    Vancouver, BC
    Posts
    15
    Thank you Missinglinq! Well that was simple, it works fine. I did not try that because ControlSource was not an option that appeared in the menu after typing in Screen.Activecontrol. Maybe the choice is not there because of my older version of access? Time to upgrade I guess .

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

Similar Threads

  1. Replies: 2
    Last Post: 05-28-2015, 12:12 PM
  2. Replies: 3
    Last Post: 05-03-2014, 03:26 AM
  3. Replies: 3
    Last Post: 03-29-2012, 12:40 PM
  4. Replies: 5
    Last Post: 10-13-2011, 03:36 PM
  5. Active X form control
    By amitsingha4u in forum Access
    Replies: 2
    Last Post: 05-18-2010, 12:21 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
  •  
Tech Forums: Microsoft Office Forums