Exit User Form Sub if Txt Box is empty

Guzzlr

Well-known Member
Joined
Apr 20, 2009
Messages
982
Office Version
  1. 2021
Platform
  1. Windows
Code:
Private Sub Btn_Compute_Click()
If Tbx_Complete Or Tbx_REV Or Tbx_Budget Or Tbx_Actual = vbNullString Then
Exit Sub
End If

Tbx_REV = (Tbx_Budget - Tbx_Actual)

End Sub

Hello All,
I have a User Form with 4 TxtBox:
Tbx_Complete
Tbx_REV
Tbx_Budget
Tbx_Actual

My "Or" syntax is wrong...and I don't know why. I'm trying to Exit the Sub, if any of the 4 TxtBox has no enty.
Thanks for the help
excel 2013
 
Last edited:

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try something like this :-
Code:
Private [COLOR="Navy"]Sub[/COLOR] CommandButton1_Click()
[COLOR="Navy"]Dim[/COLOR] Ctrl [COLOR="Navy"]As[/COLOR] Control
 [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Ctrl [COLOR="Navy"]In[/COLOR] Me.Controls
    [COLOR="Navy"]If[/COLOR] TypeName(Ctrl) = "TextBox" [COLOR="Navy"]Then[/COLOR]
       [COLOR="Navy"]If[/COLOR] Ctrl.Value = vbNullString [COLOR="Navy"]Then[/COLOR]
       MsgBox Ctrl.Name & " Has No Value"
       [COLOR="Navy"]Exit[/COLOR] [COLOR="Navy"]Sub[/COLOR]
       [COLOR="Navy"]End[/COLOR] If
    [COLOR="Navy"]End[/COLOR] If
  [COLOR="Navy"]Next[/COLOR] Ctrl
MsgBox "Do something Here, When Textboxes have values"
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Code:
Private Sub Btn_Compute_Click()
'If Tbx_Complete Or Tbx_REV Or Tbx_Budget Or Tbx_Actual = vbNullString Then
If (Tbx_Complete = vbNullString) Or (Tbx_REV = vbNullString) Or (Tbx_Budget = vbNullString) Or (Tbx_Actual = vbNullString) Then
MsgBox ("Test")
Exit Sub
End If

Tbx_REV = (Tbx_Budget - Tbx_Actual)
End Sub

WOW...I actually figured it out myself...Sort of
To compute any 1 of the fields, then 2 of the 4 fields must have a number. The problem with my code above, is when I insert a number in any of the 2 fields to find the answer, the msg box and exit sub commences.

For example, to fine Tbx_REV, then I must have Tbx_Budget and Tbx_Actual complete. However, this would keep Tbx_Complete empty, and the msgbox would display with out Tbx_REV to compute.

Thanks
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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