Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2003
    Posts
    15

    Unanswered: Referencing multiple controls

    Each of the combo boxes in my database has a corresponding text box which mirrors the item selected in the combo box. The text boxes will later be referenced for a reporting function. The selections in the combo boxes do not exactly represent the information to which they are referring, so I have to code the changes, with the changes taking place in the text box. What I have so far is below, but I know there must be an easier way to do it! Is there any way to group this request?

    If Me.txtTypeA1 = "Depth" Then
    Me.txtTypeA1 = strDepth
    End If
    If Me.txtTypeA2 = "Depth" Then
    Me.txtTypeA2 = strDepth
    End If
    If Me.txtTypeA3 = "Depth" Then
    Me.txtTypeA3 = strDepth
    End If
    If Me.txtTypeA4 = "Depth" Then
    Me.txtTypeA4 = strDepth
    End If
    If Me.txtTypeA5 = "Depth" Then
    Me.txtTypeA5 = strDepth
    End If
    If Me.txtTypeA1 = "RPR Mod" Then
    Me.txtTypeA1 = strRPRMod
    End If
    If Me.txtTypeA2 = "RPR Mod" Then
    Me.txtTypeA2 = strRPRMod
    End If
    If Me.txtTypeA3 = "RPR Mod" Then
    Me.txtTypeA3 = strRPRMod
    End If
    If Me.txtTypeA4 = "RPR Mod" Then
    Me.txtTypeA4 = strRPRMod
    End If
    If Me.txtTypeA5 = "RPR Mod" Then
    Me.txtTypeA5 = strRPRMod
    End If

  2. #2
    Join Date
    Oct 2003
    Location
    Canada
    Posts
    574
    I don't know if you can use elseif to speed it up, but I like the look of this code better:

    If Me.txtTypeA1 = "Depth" Then Me.txtTypeA1 = strDepth
    If Me.txtTypeA2 = "Depth" Then Me.txtTypeA2 = strDepth
    If Me.txtTypeA3 = "Depth" Then Me.txtTypeA3 = strDepth
    If Me.txtTypeA4 = "Depth" Then Me.txtTypeA4 = strDepth
    If Me.txtTypeA5 = "Depth" Then Me.txtTypeA5 = strDepth
    If Me.txtTypeA1 = "RPR Mod" Then Me.txtTypeA1 = strRPRMod
    If Me.txtTypeA2 = "RPR Mod" Then Me.txtTypeA2 = strRPRMod
    If Me.txtTypeA3 = "RPR Mod" Then Me.txtTypeA3 = strRPRMod
    If Me.txtTypeA4 = "RPR Mod" Then Me.txtTypeA4 = strRPRMod
    If Me.txtTypeA5 = "RPR Mod" Then Me.txtTypeA5 = strRPRMod

  3. #3
    Join Date
    Oct 2003
    Posts
    15
    I do like the look of yours better, also.

    I thought about this code. Do you think it works?

    ---------------------------------------------------

    Dim tBox As TextBox
    For Each tBox In Me.Controls
    If tBox.Name = TxtTypeA1 Or _
    tBox.Name = txtTypeA2 Or _
    tBox.Name = txtTypeA3 Or _
    tBox.Name = txtTypeA4 Or _
    tBox.Name = txtTypeA5 Then
    Select Case tBox.Text
    Case "Depth"
    tBox.Text = strDepth
    Case "RPR Mod"
    tBox.Text = strRPRMod
    End Select
    End If
    Next

  4. #4
    Join Date
    Oct 2003
    Location
    Canada
    Posts
    574
    If you don't have too many controls on the form, the last method may be faster

  5. #5
    Join Date
    Oct 2003
    Posts
    15
    It was written as a means of creating less code.

    I submitted it in code, but I received a "Type Mismatch" error. When attempting a process. I understand what a "Type Mismatch" error means, but I don't think there is a mismatch error in the code. Do you know what else could cause that?

  6. #6
    Join Date
    Oct 2003
    Location
    Canada
    Posts
    574
    try using quotes:

    If tBox.Name = "TxtTypeA1" Or _
    tBox.Name = "txtTypeA2" Or _
    tBox.Name = "txtTypeA3" Or _
    tBox.Name = "txtTypeA4" Or _
    tBox.Name = "txtTypeA5" Then

    If that does not fix it, on what line do you get the error?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •