how can i put one text box over the other one

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hannoudw
    New Member
    • Aug 2010
    • 115

    #1

    how can i put one text box over the other one

    i have 10 text box named txt_q1, txt_q2, ... , txt_q10 . on load of the form those text box are invisible.
    and another visible text box named txtsize.
    i want when i change the value of the txtsize to change the visibility of just one of the invisible text boxs.
    for example:
    if i choose txtsize=37 the txt_q1 to be visible and all the others txt_q invisible.
    if i choose txtsize=38 the txt_q2 is visible and the others invisible.
    but i want to put all the txt_q in the same place on the form, to be visible on the same spot every time that i change the txtsize.
    i tried to put them over each others and it worked but is there another way to do it , may be a vba code??
    oh ! and in the design view, i changed the layout of all the txt_q to tabular but i couldn't put them on each others after that! any one knows how or why ??
    hope that i made it clear
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32669

    #2
    It's reasonably clear. What you don't tell us is what algorithm (or formula if you prefer) should be used for choosing which of the TextBoxes should be displayed.

    I know this isn't your algorithm, but if I assume that it should work where anything up to 10 is the first, anything from there up to 20 is the second, etc, then the following might work :
    Code:
    Private Sub txtSize_AfterUpdate()
      With Me
        .txt_Q1.Visible = (.txtSize <= 10)
        .txt_Q2.Visible = ((.txtSize > 10) And (.txtSize <= 20))
        .txt_Q3.Visible = ((.txtSize > 20) And (.txtSize <= 30))
        .txt_Q4.Visible = ((.txtSize > 30) And (.txtSize <= 40))
        .txt_Q5.Visible = ((.txtSize > 40) And (.txtSize <= 50))
        .txt_Q6.Visible = ((.txtSize > 50) And (.txtSize <= 60))
        .txt_Q7.Visible = ((.txtSize > 60) And (.txtSize <= 70))
        .txt_Q8.Visible = ((.txtSize > 70) And (.txtSize <= 80))
        .txt_Q9.Visible = ((.txtSize > 80) And (.txtSize <= 90))
        .txt_Q10.Visible = (.txtSize > 90)
      End With
    End Sub
    As for the second part of your question, Tabular view assumes it is displayed in a tabular format. Overlapping controls would not be tabular, so quite sensibly, it doesn't allow you to do that.

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Rather than go through a detailed explanation of how to do this, I created a Demo for you via the Attached File.
      1. The only Form contains 10 Text Boxes named Text1 thru Text 10.
      2. Precisely position Text1 on the Form where you would like all the other Text Boxes to fall on Top of.
      3. Click the Command Button to reposition and resize all Text Boxes based on the dimensions and location of Text1.
      4. When prompted, enter a Value between 1 and 10 to make that Text Box Visible and all others Visible based again on the precise positioning and dimensions of Text1.
      5. I'll post the code for reference, but download the Attachment to really see waht is going on.
        Code:
        Dim intTBoxCtr As Integer
        Dim ctl1 As Control         'Base Text Box
        Dim ctl2 As Control         'All Other Text Boxes
        Dim varResponse As Variant
        
        Set ctl1 = Me![Text1]
        
        'Position Text1 exactly where you want all the others
        For intTBoxCtr = 2 To 10
          Set ctl2 = Me.Controls("Text" & CStr(intTBoxCtr))
            ctl2.Top = ctl1.Top
            ctl2.Height = ctl1.Height
            ctl2.Width = ctl1.Width
            ctl2.Left = ctl1.Left
        Next
        
        varResponse = InputBox$("ENTER a Text Box to make Visible (1 to 10)", "Text Box Demo")
        
        If varResponse = " " Or Not IsNumeric(varResponse) Then Exit Sub
        If varResponse > 10 Or varResponse < 1 Then varResponse = 1
                            
        'Must be OK, a Numeric Value Between 1 and 10
        For intTBoxCtr = 1 To 10
          If intTBoxCtr = varResponse Then
            Me.Controls("Text" & CStr(intTBoxCtr)).Visible = True
          Else
            Me.Controls("Text" & CStr(intTBoxCtr)).Visible = False
          End If
        Next
      Attached Files

      Comment

      • dsatino
        Contributor
        • May 2010
        • 393

        #4
        Why not just use one textbox and change the fontsize and size of the box based on the user selection?

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32669

          #5
          For the record, I quite like dsatino's suggestion. Your original idea was quite clever too, but this one is possibly even more clever :) Good thinking.

          Comment

          • hannoudw
            New Member
            • Aug 2010
            • 115

            #6
            Well thank you all , i must work on this

            Comment

            Working...