Consulting

Results 1 to 6 of 6

Thread: Macro To Not Allow Saving As When Specific Fields Are Left Blank

  1. #1

    Macro To Not Allow Saving As When Specific Fields Are Left Blank

    Hi, can someone please help me create a macro on my file. I want the user to not be able to save the file unless he has filled-out the fields I have tagged in red font. I want an error message to prompt user that the required fields should be populated first before saving as.

    I have posted a similar question before but that is on printing. This time I would like to prevent Saving As when my required fields are not complete filled-out.

    http://www.vbaexpress.com/forum/showthread.php?t=34056

    Thanks in advance!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Just use the BeforeSave event instead of the BeforePrint event.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Thanks xld but it does not work for me. I tried it. I dunno whats wrong..

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    What did you try?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    I tried this code :
    [VBA]
    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Dim msg As String

    With ActiveSheet

    If .Range("I19").Value2 = "" Then

    msg = msg & vbTab & "Missing Vendor Name" & vbNewLine
    End If

    If .Range("C29").Value2 = "" Then

    msg = msg & vbTab & "Missing Street House Number" & vbNewLine
    End If

    'etc

    If msg <> "" Then

    msg = "Missing items: " & vbNewLine & vbNewLine _
    & msg & vbNewLine & vbNewLine _
    & "Correct and resubmit!!!" & vbNewLine & vbNewLine

    MsgBox msg, vbExclamation, "Save As Failure"
    Cancel = True
    End If
    End With
    End Sub[/VBA]
    Last edited by Bob Phillips; 09-23-2010 at 07:21 AM. Reason: Added VBA Tags

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I just plugged that code into your workbook and it worked fine.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •