How can I dynamically select the form field to assign to a variable in VBA

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • parrib1
    New Member
    • Sep 2010
    • 2

    #1

    How can I dynamically select the form field to assign to a variable in VBA

    Code:
    Dim formItemS As String, ParmString As String
    ParmString = "TelephoneNum1"
    
    formItemS = Forms!frmMacRequestsInputAdd!TelephoneNum1
    Debug Results
    Code:
    ? formItemS
    5555555555
    I want to do this and get 5555555555
    Code:
    formItemS = Forms!frmMacRequestsInputAdd!ParmString
    I need to know how to dynamicaly input which field to move to formItems.
    Last edited by NeoPa; Sep 10 '10, 01:17 PM. Reason: Please use the [CODE] tags provided
  • MikeTheBike
    Recognized Expert Contributor
    • Jun 2007
    • 640

    #2
    Hi

    Maybe somthing like this
    Code:
    Dim formItemS As String, ParmString As String
    ParmString = "TelephoneNum1"
    
    formItemS = Forms("frmMacRequestsInputAdd").Controls(ParmString)
    
    
    MsgBox formItemS
    ??

    MTB

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32669

      #3
      Quite right. An alternative for line #4 would be :
      Code:
      formItemS = Forms!frmMacRequestsInputAdd.Controls(ParmString)

      Comment

      • parrib1
        New Member
        • Sep 2010
        • 2

        #4
        Exactly It

        That was exactly what I needed. I knew it was something relatively simple.

        Thank you very much!!

        Comment

        Working...