help with userform

clares

Well-known Member
Joined
Mar 14, 2002
Messages
557
Hi All

I have a userform and I want to make sure that the contents of a textbox doesnt contain either a 0 or an empy ("") value.

I am checking this on Initialization, OnChange and OnExit. It works ok apart from the part that resets the focus to the textbox that I want to user to complete. On Exiting the textbox, it runs through the code and executes the line setting the focus, but when it come to the end of the code (End Sub), the cursor goes to back to the textbox that the user click into when they exited the textbox that requires the value.

Obviously no geeting this to work could mean that the values won't be present when it comes to do the required calculations!

My code for the Exit is:
Code:
Private Sub txtProgressCostPrice_Exit(ByVal Cancel As MSForms.ReturnBoolean)

    If frmCalculatePrice.txtProgressCostPrice = 0 Or frmCalculatePrice.txtProgressCostPrice = "" Then
        MsgBox "You must enter a COST PRICE for this product"
        frmCalculatePrice.txtProgressCostPrice.Enabled = True
        frmCalculatePrice.txtProgressCostPrice.SetFocus
    Else
        frmCalculatePrice.txtProgressCostPrice = FormatCurrency(txtProgressCostPrice, -1)
        frmCalculatePrice.txtProgressCostPrice.Enabled = False
    End If
End Sub

Does anyone know what I am doing wrong or can help!

Kindest Regards

Peter
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Juan Pablo González

MrExcel MVP
Joined
Feb 8, 2002
Messages
11,959
Try using the BeforeUpdate event. Set the "Cancel" parameter to True if you don't want to allow the user to exit that textbox.
 

clares

Well-known Member
Joined
Mar 14, 2002
Messages
557
Thanks

How do I set the cancel paremeter to true please?

Kindest Regards

Peter
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,096
Messages
5,768,068
Members
425,451
Latest member
JohnBrooksBiddle

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
Top