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.)
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:
For Clear Button:
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