|
-
Jul 20th, 2009, 02:37 AM
#1
Thread Starter
New Member
Excel VB Form
Hoping someone can help.
I am creating a form using Excel and VB and am ttrying to make some of the fileds validate, to make sure the user has filled in all the required fileds before the form is printed.
I am using the code below, but for some reason, is the answer clicked on the Yes/No box is NO, the form deletes out the content of the fileds but doesn't continue on to print.
Can someone please help?
Code:
If Desc2 <> "" And Quant2 = "" Then
Msg = "You have entered in a 2nd item Description but not a Quantity." & vbCrLf & vbCrLf & "Did you mean to fill in the 2nd item Description?"
Style = vbYesNo + vbExclamation
Title = "Warning"
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
Range("F55").Select
Else
Range("A55:H55").Select
Selection.ClearContents
End If
Exit Sub
Else
End If
Sheets("Form").Select
Application.ActivePrinter = "CutePDF Writer on CPW2:"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("Data").Select
Range("C9:d9").Select
End Sub
Thanks
Last edited by Hack; Jul 20th, 2009 at 06:25 AM.
Reason: Added Code Tags
-
Jul 20th, 2009, 06:25 AM
#2
Re: Excel VB Form
Excel VBA Question Moved To Office Development
-
Jul 20th, 2009, 10:55 AM
#3
Re: Excel VB Form
That's because you have told it to Exit Sub regardless of whether the user clicks Yes or No.
-
Jul 20th, 2009, 12:23 PM
#4
Re: Excel VB Form
If you format your code it will be easier to see why it exits 
Code:
If Desc2 <> "" And Quant2 = "" Then
Msg = "You have entered in a 2nd item Description but not a Quantity." & vbCrLf & vbCrLf & "Did you mean to fill in the 2nd item Description?"
Style = vbYesNo + vbExclamation
Title = "Warning"
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
Range("F55").Select
Else
Range("A55:H55").Select
Selection.ClearContents
End If
Exit Sub
Else
End If
Sheets("Form").Select
Application.ActivePrinter = "CutePDF Writer on CPW2:"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("Data").Select
Range("C9:d9").Select
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|