UserForm MessageBox Options?

aka_krakur

Active Member
Joined
Jan 31, 2006
Messages
438
I have the following VB macro that runs after user presses OK on a userform. I don't think it's written correctly. I would like a prompt that gives two options (either yes to return a null value if they've left a field blank, or return user to a reset userform1 if they select no.)

Code:
Private Sub CommandButton1_Click()

If Me.TextBox1.Value = "" Then
MsgBox ("You Must Enter a Part Number (eg. 1007821-12)")
Unload UserForm1
Calculate
UserForm1.Show
End If
If Me.TextBox2.Value = "" Then
MsgBox ("You Must Enter a Lot Number (eg. 6020631)")
Unload UserForm1
Calculate
UserForm1.Show
End If

If Me.TextBox3.Value = "" Then
MsgBox ("You Must Enter a Current Incident # (eg. 93885)")
Unload UserForm1
Calculate
UserForm1.Show
End If

'Unload UserForm
Sheets("Similar Incident Query Template").Select
Unload UserForm1
' Refresh data
 Application.ScreenUpdating = False
' Add UserForm data to proper fields
Sheets("Similar Incident Query Template").Range("B9").Value = Me.TextBox1.Value
Calculate
Sheets("Similar Incident Query Template").Range("B10").Value = Me.TextBox2.Value
Calculate
Sheets("Similar Incident Query Template").Range("B11").Value = Me.TextBox3.Value
Calculate
Sheets("Similar Incident Query Template").Range("C15").Select
Calculate
Selection.QueryTable.Refresh BackgroundQuery:=True
Range("H15").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-1]=R[1]C[-1],""Duplicate"",""Unique"")"
Calculate
Range("G15").Select
ActiveCell.FormulaR1C1 = "=CONCATENATE(RC[2],-RC[3],-RC[4])"
Calculate
last1 = Range("C65536").End(xlUp).Row
    Range("H15").Select
    Selection.AutoFill Destination:=Range("H15:H" & last1)
    Range("G15").Select
    Selection.AutoFill Destination:=Range("G15:G" & last1)
Calculate
End Sub

1. For some reason I don't think I have the code the way I truly want it on the "MsgBox"... and regardless,
2. I am actually wanting to either create another userform or something similar to a msgbox that prompts the user "Do you really want to leave this field blank"...if they choose Yes, then it returns a true null value; but if they choose No, then it brings them back to the "reset" form.
3. Other problem I have with the way the code is currently, is if they did leave a field blank and it brings them back to the userform, if I select Cancel, it still pops up with one of those Msgboxes.

the code for the Cancel button is quite simple:

Code:
Private Sub CommandButton4_Click()
'Cancel using form
Sheets("Similar Incident Query Template").Select
Unload UserForm1
End Sub

For Clear Button:
Code:
Private Sub CommandButton3_Click()
'Clear UserForm
Unload UserForm1
UserForm1.Show

End Sub
 
Okay.
Now I just can't figure out what code to put into the vbYes and vbNo
Code:
rsp = MsgBox("Do you really want to leave the Part Number blank?", vbYesNo)
Select Case rsp
       Case vbYes
            ' code if user wants to leave blank
            
       Case vbNo
            ' code to return user to form
End Select
If User has selected Yes at this point...then I just need the macro to continue as is.
If User selects No, I need it to halt the macro until user has input something into this field on the UserForm.

I have no idea how to do this
 
Upvote 0

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
I feel stupid...I guess Exit Sub works, which just comes right back to the UserForm1 as it was left by the user (with the blank).
I think that irons out the kinks.

We'll see.
 
Upvote 0

Forum statistics

Threads
1,224,800
Messages
6,181,045
Members
453,014
Latest member
Chris258

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