Results 1 to 4 of 4
  1. #1
    bonecone is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2012
    Posts
    25

    Question Using string manipulation to assign form controls to variables


    I have three sets of controls whose names are the same except for their suffixes. I want to be able to pass the name suffix into a procedure as a string in order to specify which set of controls I want the procedure to focus on.

    Code:
    Call TestProcedure("ControlNameSuffix")
    
    Public Sub TestProcedure(ControlNameSuffix As String)
    
         Dim TestControl As Control
         Set TestControl = "ControlNamePrefix" & ControlNameSuffix
    
         MsgBox(TestControl.Value)
    End Sub
    But this just gives me a type mismatch error. How can I do this using String manipulation?

  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,530
    Presuming on the same form:

    MsgBox Me("ControlNamePrefix" & ControlNameSuffix)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    bonecone is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2012
    Posts
    25
    Thanks!

    Actually it was in a separate code module. I used the syntax

    MsgBox(Form_frmName("ControlNamePrefix" & ControlNameSuffix).Value)

  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,530
    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: 3
    Last Post: 03-28-2012, 10:16 AM
  2. Assign Combo Box from Main form to Subform
    By tbassngal in forum Forms
    Replies: 5
    Last Post: 07-18-2011, 04:11 PM
  3. Form output data manipulation
    By bearsgone in forum Forms
    Replies: 1
    Last Post: 04-05-2011, 04:21 PM
  4. Form manipulation error
    By witooldas in forum Forms
    Replies: 6
    Last Post: 03-18-2011, 02:40 AM
  5. Form Manipulation examples
    By pkstormy in forum Code Repository
    Replies: 0
    Last Post: 08-24-2010, 12:03 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