Results 1 to 4 of 4
  1. #1
    Gerry is offline Rusty Developer
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    Kings Mountain, NC
    Posts
    33

    Using a string variable to specify a control

    I have a need to be able to clear specific combo boxes when certain actions are taken. To do this efficiently, I need to be able to use string variables (or similar) to identify the correct combo to be cleared. Several searches across the web have yielded no insight into a solution.



    Below is my first attempt, which obviously doesn't work. When it hits the SET line, I get "...can't find the field 'strCombo' referred to...". Obviously, it's looking for an object, rather than a string. How can I use a string to identify which object I need? It seems external-facing functions, like GetObject, are designed to work this way. Is there a similar function that I can use for Access objects?


    Public Function ClearCombo(frm As Form)

    On Error GoTo Err_Handler

    Dim strCommand As String ' used for retrieving the name of the current control
    Dim strSelect As String ' used to store the ID number of the current button
    Dim lngPosition As Long ' used to store the position of the underscore character
    Dim strCombo As String ' used to build the name of the combo box
    Dim cbo As ComboBox

    strCommand = Screen.ActiveControl.Name
    lngPosition = InStr(1, "_", strCommand, vbTextCompare)
    strSelect = Right(strCommand, Len(strCommand) - (lngPosition + 1))
    strCombo = "cboLead_" & strSelect

    Set cbo = frm!strCombo
    cbo.Value = Null

    Exit_Handler:
    Exit Function

    Err_Handler:
    Call LogError(Err.Number, Err.Description, "ClearCombo")
    Resume Exit_Handler

    End Function

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Try

    frm.Controls(strCombo)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Gerry is offline Rusty Developer
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    Kings Mountain, NC
    Posts
    33

    Solved!

    Hehe! Posted this at two forums, since the first dozen views didn't yield a reply. You and someone on the other forum posted within about 2 minutes of each other, both with the exact same CORRECT reply. Thanks!

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

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

Similar Threads

  1. Replies: 5
    Last Post: 04-05-2010, 11:43 AM
  2. using forms control as report variable
    By Seven in forum Reports
    Replies: 3
    Last Post: 12-19-2009, 04:04 PM
  3. Variable Criteria
    By JamesLens in forum Queries
    Replies: 0
    Last Post: 01-02-2009, 04:55 PM
  4. Variable question
    By synapse5150 in forum Programming
    Replies: 1
    Last Post: 07-09-2008, 08:17 AM
  5. Sending control to specific control
    By wasim_sono in forum Programming
    Replies: 2
    Last Post: 04-19-2007, 08:19 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