error message pop up

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Error message to pop up if all fields haven't been completed

Error message to pop up if all fields haven't been completed

resolvedResolved · High Priority · Version 2016

Vicki has attended:
Excel VBA Introduction course

Error message to pop up if all fields haven't been completed

Hi, I want to write something which says if any of the grouped radio buttons have been left blank - i.e. you need to select at least one in each group, then when you click on the 'create' button at the bottom you get a pop up error saying "Incomplete form" or something, forcing the user to complete all fields before the document is produced. I've put my full Script below FYI which is working on it's own, not sure where I would need to put this new bit either as it needs to pop up after they try to submit and I probably need to say if all fields have been completed correctly then carry on with this below. Any help would be much appreciated.

Option Explicit

Private Sub CommandButton1_Click()


Dim wapp As Word.Application
Dim wdoc As Word.Document
If Me.OptionButton1 = True Then
Set wapp = CreateObject("Word.Application")
Set wdoc = wapp.Documents.Open("\\emea.ajgco.com\emeadata\vol1\SoDaN Test\Gallagher\PI Sodan Advised AJG Wholesale1.dotx")
wapp.Visible = True
ElseIf Me.OptionButton2 = True Then
Set wapp = CreateObject("Word.Application")
Set wdoc = wapp.Documents.Open("\\emea.ajgco.com\emeadata\vol1\SoDaN Test\Gallagher\PI Sodan Advised AJG1.dotx")
wapp.Visible = True
End If

If Me.OptionButton3 = True Then
wapp.Selection.Goto what:=wdGoToBookmark, Name:="NewRenewal"
wapp.Selection.TypeText Sheet2.Range("b15")
ElseIf Me.OptionButton4 = True Then
wapp.Selection.Goto what:=wdGoToBookmark, Name:="NewRenewal"
wapp.Selection.TypeText Sheet2.Range("b16")
End If

wapp.Selection.Goto what:=wdGoToBookmark, Name:="Insured"
wapp.Selection.TypeText ActiveSheet.TextBox2

wapp.Selection.Goto what:=wdGoToBookmark, Name:="Type1"
wapp.Selection.TypeText ActiveSheet.ComboBox1

wapp.Selection.Goto what:=wdGoToBookmark, Name:="Type2"
wapp.Selection.TypeText ActiveSheet.ComboBox1

wapp.Selection.Goto what:=wdGoToBookmark, Name:="Type3"
wapp.Selection.TypeText ActiveSheet.ComboBox1

wapp.Selection.Goto what:=wdGoToBookmark, Name:="Insurer"
wapp.Selection.TypeText ActiveSheet.ComboBox2

If Me.OptionButton9 = True Then
wapp.Selection.Goto what:=wdGoToBookmark, Name:="AddOns"
wapp.Selection.TypeText Sheet2.Range("b2")
ElseIf Me.OptionButton10 = True Then
wapp.Selection.Goto what:=wdGoToBookmark, Name:="AddOns"
wapp.Selection.TypeText Sheet2.Range("b3")
End If

If Me.OptionButton5 = True Then
wapp.Selection.Goto what:=wdGoToBookmark, Name:="MarketStrategy"
wapp.Selection.TypeText Sheet2.Range("b11")
ElseIf Me.OptionButton6 = True Then
wapp.Selection.Goto what:=wdGoToBookmark, Name:="MarketStrategy"
wapp.Selection.TypeText Sheet2.Range("b12")
End If


If Me.OptionButton7 = True Then
wapp.Selection.Goto what:=wdGoToBookmark, Name:="PenInvolvement"
wapp.Selection.TypeText Sheet2.Range("b8")
ElseIf Me.OptionButton8 = True Then
wapp.Selection.Goto what:=wdGoToBookmark, Name:="PenInvolvement"
wapp.Selection.TypeText " "
End If

If Me.OptionButton11 = True Then
wapp.Selection.Goto what:=wdGoToBookmark, Name:="BinderNonBinder"
wapp.Selection.TypeText Sheet2.Range("b20")
ElseIf Me.OptionButton12 = True Then
wapp.Selection.Goto what:=wdGoToBookmark, Name:="BinderNonBinder"
wapp.Selection.TypeText Sheet2.Range("b19")
End If

If Me.OptionButton13 = True Then
wapp.Selection.Goto what:=wdGoToBookmark, Name:="DaNFullyMet"
wapp.Selection.TypeText Sheet2.Range("b5")
ElseIf Me.OptionButton14 = True Then
wapp.Selection.Goto what:=wdGoToBookmark, Name:="DaNFullyMet"
wapp.Selection.TypeText Sheet2.Range("b6")
End If

If ActiveSheet.TextBox3 = "" Then
GoTo ContinueNext
Else
wapp.Selection.Goto what:=wdGoToBookmark, Name:="CommentsOnNotMeetingNeeds"
wapp.Selection.TypeText ActiveSheet.TextBox3
End If

ContinueNext:
If ActiveSheet.TextBox3 = "" Then
wapp.Selection.Goto what:=wdGoToBookmark, Name:="CommentsOnNotMeetingNeeds"
wapp.Selection.TypeText " "
End If


End Sub

Private Sub OptionButton5_Click()

End Sub



RE: Error message to pop up if all fields haven't been completed

Hi Vicki,

Thank you for the forum question.

Try

Option Explicit

Private Sub CommandButton1_Click()


Dim wapp As Word.Application
Dim wdoc As Word.Document

If Me.OptionButton1=False And Me.OptionButton1=False then
Msgbox "Please select an Option"
Exit Sub
End If

If Me.OptionButton3=False And Me.OptionButton4=False then
Msgbox "Please select an Option"
Exit Sub
End If

If Me.OptionButton9=False And Me.OptionButton10=False then
Msgbox "Please select an Option"
Exit Sub
End If

If Me.OptionButton5=False And Me.OptionButton6=False then
Msgbox "Please select an Option"
Exit Sub
End If

If Me.OptionButton7=False And Me.OptionButton8=False then
Msgbox "Please select an Option"
Exit Sub
End If

If Me.OptionButton1 = True Then
Set wapp = CreateObject("Word.Application")
Set wdoc = wapp.Documents.Open("\\emea.ajgco.com\emeadata\vol1\SoDaN Test\Gallagher\PI Sodan Advised AJG Wholesale1.dotx")
wapp.Visible = True
ElseIf Me.OptionButton2 = True Then
Set wapp = CreateObject("Word.Application")
Set wdoc = wapp.Documents.Open("\\emea.ajgco.com\emeadata\vol1\SoDaN Test\Gallagher\PI Sodan Advised AJG1.dotx")
wapp.Visible = True
End If

If Me.OptionButton3 = True Then
wapp.Selection.Goto what:=wdGoToBookmark, Name:="NewRenewal"
wapp.Selection.TypeText Sheet2.Range("b15")
ElseIf Me.OptionButton4 = True Then
wapp.Selection.Goto what:=wdGoToBookmark, Name:="NewRenewal"
wapp.Selection.TypeText Sheet2.Range("b16")
End If

wapp.Selection.Goto what:=wdGoToBookmark, Name:="Insured"
wapp.Selection.TypeText ActiveSheet.TextBox2

wapp.Selection.Goto what:=wdGoToBookmark, Name:="Type1"
wapp.Selection.TypeText ActiveSheet.ComboBox1

wapp.Selection.Goto what:=wdGoToBookmark, Name:="Type2"
wapp.Selection.TypeText ActiveSheet.ComboBox1

wapp.Selection.Goto what:=wdGoToBookmark, Name:="Type3"
wapp.Selection.TypeText ActiveSheet.ComboBox1

wapp.Selection.Goto what:=wdGoToBookmark, Name:="Insurer"
wapp.Selection.TypeText ActiveSheet.ComboBox2

If Me.OptionButton9 = True Then
wapp.Selection.Goto what:=wdGoToBookmark, Name:="AddOns"
wapp.Selection.TypeText Sheet2.Range("b2")
ElseIf Me.OptionButton10 = True Then
wapp.Selection.Goto what:=wdGoToBookmark, Name:="AddOns"
wapp.Selection.TypeText Sheet2.Range("b3")
End If

If Me.OptionButton5 = True Then
wapp.Selection.Goto what:=wdGoToBookmark, Name:="MarketStrategy"
wapp.Selection.TypeText Sheet2.Range("b11")
ElseIf Me.OptionButton6 = True Then
wapp.Selection.Goto what:=wdGoToBookmark, Name:="MarketStrategy"
wapp.Selection.TypeText Sheet2.Range("b12")
End If


If Me.OptionButton7 = True Then
wapp.Selection.Goto what:=wdGoToBookmark, Name:="PenInvolvement"
wapp.Selection.TypeText Sheet2.Range("b8")
ElseIf Me.OptionButton8 = True Then
wapp.Selection.Goto what:=wdGoToBookmark, Name:="PenInvolvement"
wapp.Selection.TypeText " "

End If




Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

Thu 1 Nov 2018: Automatically marked as resolved.

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Paste with Live Preview in Excel 2010

Did you know you can preview what you are about to paste? Here's how to do it.

Copy what you are about to paste
Position the cursor where you want to paste
Right click to display the shortcut menu
Place the cursor over the Paste Options and this will give you a preview of the what you are about to paste.

View all Excel hints and tips


Server loaded in 0.07 secs.