• Dynamically load values to controls

    Author
    Topic
    #463363

    Working on this, thought i’d ask around…

    I want to create a button that will load user edit controls with data from companion controls that only display preloaded data. one way to identify the preloaded controls is to add a tag to them, and this allows me to cycle thru and find the name/value pairs for the preloaded data.

    the fun begins when i try to assemble a control name in code and assign it the value fetched:

    [codebox]Private Sub btnValuesToUserEdits_Click()
    Dim UserCtlString As String
    Dim UserCtl As Control
    Dim ctl As Control
    For i = 0 To 7
    For Each ctl In Me.MainTab.Pages(i).Controls
    With ctl
    If .Tag = “OR” Then
    ControlName = .Name
    ControlValue = .Value
    UserCtlString = “UE_” & ControlName <– this gives me a valid control name
    UserCtl = UserCtlString <– this doesn't work
    UserCtl.Value = ControlValue
    End If
    End With
    Next
    Next i

    End Sub[/codebox]

    Essentially I want a variable that specifies an existing control, find the control and load it with the value in the tagged control. now, perhaps this is going to have to be some sort of array to load value/pairs and an additional array to step thru controls and map the values but i was hoping to do this in a single loop. no good reason, just seems a lot easier. That doesn't mean it can be done, of course…

    TIA

    Viewing 1 reply thread
    Author
    Replies
    • #1182631

      Working on this, thought i’d ask around…

      I want to create a button that will load user edit controls with data from companion controls that only display preloaded data. one way to identify the preloaded controls is to add a tag to them, and this allows me to cycle thru and find the name/value pairs for the preloaded data.

      the fun begins when i try to assemble a control name in code and assign it the value fetched:

      [codebox]Private Sub btnValuesToUserEdits_Click()
      Dim UserCtlString As String
      Dim UserCtl As Control
      Dim ctl As Control
      For i = 0 To 7
      For Each ctl In Me.MainTab.Pages(i).Controls
      With ctl
      If .Tag = “OR” Then
      ControlName = .Name
      ControlValue = .Value
      UserCtlString = “UE_” & ControlName <– this gives me a valid control name
      UserCtl = UserCtlString <– this doesn't work
      UserCtl.Value = ControlValue
      End If
      End With
      Next
      Next i

      End Sub[/codebox]

      Essentially I want a variable that specifies an existing control, find the control and load it with the value in the tagged control. now, perhaps this is going to have to be some sort of array to load value/pairs and an additional array to step thru controls and map the values but i was hoping to do this in a single loop. no good reason, just seems a lot easier. That doesn't mean it can be done, of course…

      TIA

      Firstly you would need to use set to assign to a control variable
      and you cannot just assign it a string it has to relate to the Forms Control Collection

      Try something like

      SET UserCtl = ME(UserCtlString) '<– this ought to work

    • #1182654

      thanks! worked like a charm.

    Viewing 1 reply thread
    Reply To: Dynamically load values to controls

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: