+ Reply to Thread
Results 1 to 5 of 5

Locked textbox clears text when command button clicked.

Hybrid View

  1. #1
    Registered User
    Join Date
    10-23-2012
    Location
    china
    MS-Off Ver
    Excel 2010
    Posts
    12

    Locked textbox clears text when command button clicked.

    Hi all,

    I have a userform with a textbox, combobox and a command button. The textbox is already locked in the properties.

    Item 1 of the combobox will do .find operation and displays the result in the textbox upon clicking the button.
    Item 2 of the combobox will do autofilter operation, store the filtered data in an arrary and display the array data in the textbox when the button clicked.

    Both operations display result in the textbox just fine. I wanted the text in the textbox to be locked so that no changes can be made on the display result.
    The problem is, text result of the autofilter disappears when mouse click in textbox. But this doesnt happen for the .find operation.


    What may the cause of this problem? Could anyone help me with this?

    Thanks in advance.

  2. #2
    Forum Contributor
    Join Date
    01-02-2007
    Location
    Australia NSW
    MS-Off Ver
    2013
    Posts
    494

    Re: Locked textbox clears text when command button clicked.

    Use
    Texbox1.Enabled = False
    It will prevent the user entering it.
    Also make sure you do not have any Textbox1 enter scripts that may be clearing it.

  3. #3
    Registered User
    Join Date
    10-23-2012
    Location
    china
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Locked textbox clears text when command button clicked.

    i tried to use

    TextBox1.Enable = False
    i dont want to disable the textbox as it will make the text turn grey colour. Or is there a way to change the text colour of the disable textbox into black?

  4. #4
    Registered User
    Join Date
    10-23-2012
    Location
    china
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Locked textbox clears text when command button clicked.

    Here is my code for the autofilter operation.. Everything works fine, until the user click in the textbox and the text disappears. I wanted the text in the textbox to be locked so that it will not disappears when user clicks the textbox.

    Could anyone help me with this? Thanks

    If Me.ComboBox2.BoundValue = vbNullString Then
            MsgBox "Please select search option !", vbOKOnly
            Exit Sub
        Else
            
            If Me.ComboBox2.BoundValue = "Date" Then
          
    '          If Me.ComboBox1.BoundValue = "Test " Then  'And Me.ComboBox2.BoundValue = "Date" Then
                If Me.ComboBox4.BoundValue = vbNullString Or Me.ComboBox5.BoundValue = vbNullString Then
                    MsgBox "Please select Month & Year!", vbOKOnly
                    Exit Sub
                Else
                    Sheet2.Range("$P$3:$Q$34").AutoFilter Field:=1, Criteria1:=ComboBox4.Value
                    Sheet2.Range("$P$3:$Q$34").AutoFilter Field:=2, Criteria1:=ComboBox5.Value
                    
                    count = 0
                    Set visrng = Range("A3:A" & Cells(Rows.count, 1).End(xlUp).row).SpecialCells(xlCellTypeVisible)
                 
                    If (visrng.row < 3) Then
                        With TextBox1
                            .MultiLine = True
                            .FontBold = True
                            .Text = " No due in this month "
                        End With
                        Sheet2.ShowAllData
                    Else
                        For Each rw In visrng
                            row = rw.row
                            DateArray(count, 0) = count
                            DateArray(count, 1) = Sheet2.Cells(row, 7)
                            DateArray(count, 2) = Sheet2.Cells(row, 18)
                            count = count + 1
                        Next rw
    
                        For i = 1 To 34
                            out = out & Format(DateArray(i, 0)) & vbTab
                            out = out & Format(DateArray(i, 1)) & vbNewLine
                            out = out & vbTab & Format(DateArray(i, 2)) & vbTab & vbNewLine
    
                            out = out & vbCrLf
                        Next i
    
                        With TextBox1
                            .MultiLine = True
                            .FontBold = True
                            .Text = "List for the month of " & ComboBox4.Value & " " & ComboBox5.Value & Chr(13) & Chr(13) & out
                            .ForeColor = &H80000012
                            
                        End With
                        Sheet2.ShowAllData
                    End If
                    Exit Sub
                 End If
    Last edited by cocobean; 11-14-2012 at 02:48 AM.

  5. #5
    Registered User
    Join Date
    10-23-2012
    Location
    china
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Locked textbox clears text when command button clicked.

    Could anyone help me with this?

    I've been trying to solve this problem for few days. All the logic works fine but the text in the textbox disappears on mouse click? I already locked the textbox in the properties? Why did this happened? Is there anything wrong with my logic/codes?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1