Textbox wont allow set focus on it after trying to clear textboxes

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,731
Office Version
  1. 2007
Platform
  1. Windows
When i try to clear the values on my userform i see the following error message
Type Mismatch,i debug & see the line of code in yellow highlighted

The Textbox in question that gives me the issue is called CustomerID

Rich (BB code):
    Dim id As Integer, rowcount As Integer, foundcell As Range
    
    id = CustomerID.Value
    
    rowcount = Sheets("G INCOME").Cells(Rows.Count, 13).End(xlUp).Row ' THIS IS COLUMN NUMBER WHERE EMP ID LOCATED
    
    With Worksheets("G INCOME").Range("M1:M" & rowcount) ' THIS IS CELL REFERENCE OF WHERE THE TEXT EMP ID IS LOCATED
        Set foundcell = .Find(what:=id, LookIn:=xlValues)
        
        If Not foundcell Is Nothing Then
            TextBox1.Value = .Cells(foundcell.Row, 2)
            TextBox2.Value = .Cells(foundcell.Row, 3)
            TextBox3.Value = .Cells(foundcell.Row, 4)
            TextBox4.Value = .Cells(foundcell.Row, 5)
            TextBox5.Value = .Cells(foundcell.Row, 6)
        
         Else
            TextBox1.Value = ""
            TextBox2.Value = ""
            TextBox3.Value = ""
            TextBox4.Value = ""
            TextBox5.Value = ""
            
        End If
        
    End With
    
End Sub

This is how i clear & try to set focus in the textboxes.

Rich (BB code):
Private Sub ClearValues_Click()
CustomerID = ""
TextBox1 = ""
TextBox2 = ""
TextBox3 = ""
TextBox4 = ""
TextBox5 = ""
CustomerID.SetFocus


End Sub
 
So this works now thanks.

Rich (BB code):
Private Sub ClearValues_Click()
CustomerID = ""
TextBox1 = ""
TextBox2 = ""
TextBox3 = ""
TextBox4 = ""
TextBox5 = ""
CustomerID.SetFocus

End Sub

So Integer relates to a number.

Variant means number or letter, is that correct ?
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I don't know what anyone else suggested you do. Perhaps you didn't actually do that anyway, because there was no yellow text or highlight. From what I've seen elsewhere in these forums, people use Rich BB tags and format their code using bold and coloured fonts. Then the vba code gets all messed up with interspersed rtf (Rich Text Format) tags. I tried to find an example for you but the search function ignores the tag characters that I try to search on. I can't see the value in that over what I showed you but you are free to do what you think will ensure the reader gets a clear indication of where the problem lies.
 
Upvote 0
I mentioned the line of code that was the issue.

I said I had a run time error and when debugged the line of code was shown in Yellow.

In my post here yellow show up so I had shown it in red but I was referring to the yellow when I debug it.

Anyway with your advice it’s now working.

Thanks again.
 
Upvote 0

Forum statistics

Threads
1,223,878
Messages
6,175,141
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top