Results 1 to 4 of 4

Thread: Excel VB Form

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    1

    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

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Excel VB Form

    Excel VBA Question Moved To Office Development

  3. #3
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: Excel VB Form

    That's because you have told it to Exit Sub regardless of whether the user clicks Yes or No.
    I use VB 6, VB.Net 2003 and Office 2010



    Code:
    Excel Graphing | Excel Timer | Excel Tips and Tricks | Add controls in Office | Data tables in Excel | Gaussian random number distribution (VB6/VBA,VB.Net) | Coordinates, Vectors and 3D volumes

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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
  •  



Click Here to Expand Forum to Full Width