setting focus on a textbox

nobenbien

New Member
Joined
Jul 25, 2011
Messages
4
i made a userform with 2 textboxes (textbox1 and textbox2), and i added a button to the userform.

i also made a classmodule: checkinput
this module contains a function ispresent

The code reads:

Function ispresent(ByVal textbox As msforms.textbox) As Boolean
If textbox.Text = "" Or Not IsNumeric(textbox) Then
textbox.SetFocus ' here is my problem
ispresent = False
Else
ispresent = True
End If
End Function

the code in the userformmodule calls this function.

if the function ispresent is called and the passed textbox on the userforms contains nothing or a number, i want the focus be set on that particular textbox.

What happens is that the focus is being set but.. only for a fraction of a second.

what am i doing wrong?

Can anyone give me a hint.


Thx
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
How are you calling the function? From an exit event?
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,345
Members
452,907
Latest member
Roland Deschain

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