+ Reply to Thread
Results 1 to 5 of 5

IsBlank function run on form will not allow initial save of bank value to send to users

Hybrid View

lengwer IsBlank function run on form... 06-17-2014, 12:29 PM
slx Re: IsBlank function run on... 06-17-2014, 01:27 PM
LJMetzger Re: IsBlank function run on... 06-17-2014, 05:54 PM
lengwer Re: IsBlank function run on... 06-18-2014, 10:01 AM
lengwer Re: IsBlank function run on... 06-18-2014, 10:03 AM
  1. #1
    Registered User
    Join Date
    08-14-2013
    Location
    Kentucky, United States
    MS-Off Ver
    03,07,10
    Posts
    61

    IsBlank function run on form will not allow initial save of bank value to send to users

    I have the following code to prevent users from being able to save the form blank to send. However I need to be able to send the user a blank form innitially I can not figure out how to do this, Please advise.

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    
    If IsEmpty(ThisWorkbook.Sheets(1).Range("B6")) Then
            MsgBox ("Must enter Supplier Name")
            Cancel = True
        Else
        If IsEmpty(ThisWorkbook.Sheets(1).Range("C6")) Then
           MsgBox ("Must enter Supplier Location")
           Cancel = True
        Else
        If IsEmpty(ThisWorkbook.Sheets(1).Range("D6")) Then
           MsgBox ("Please enter your 5 digit supplier code. If you need assistance with the supplier code please contact SSG at 1(800)782-8099")
           Cancel = True
        Else
        If IsEmpty(ThisWorkbook.Sheets(1).Range("B10")) Then
           MsgBox ("Please enter expected users First name")
           Cancel = True
        Else
        If IsEmpty(ThisWorkbook.Sheets(1).Range("C10")) Then
           MsgBox ("Please enter expected users Last name")
           Cancel = True
        Else
        If IsEmpty(ThisWorkbook.Sheets(1).Range("D10")) Then
           MsgBox ("Please Create an original SSO # for this user")
           Cancel = True
        Else
        If IsEmpty(ThisWorkbook.Sheets(1).Range("F10")) Then
           MsgBox ("Please enter expected users email address.      Note: This must be a complete and existing email address")
           Cancel = True
        Else
        If IsEmpty(ThisWorkbook.Sheets(1).Range("G10")) Then
           MsgBox ("Please enter expected users full phone number with area code")
           Cancel = True
    
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    
    End Sub

  2. #2
    Forum Contributor
    Join Date
    04-24-2007
    Location
    NYC
    MS-Off Ver
    2k3/2k7/2010
    Posts
    270

    Re: IsBlank function run on form will not allow initial save of bank value to send to user

    Disable macros before opening this file. Then fix your code, and save.

  3. #3
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: IsBlank function run on form will not allow initial save of bank value to send to user

    Hi lengwer,

    To iniitialize your data try the following in an ordinary code module such as 'Module1':
    Sub InitializeFormCells()
    
        With ThisWorkbook.Sheets(1)
            Range("B6") = ""
            Range("C6") = ""
            Range("D6") = ""
            Range("B10") = ""
            Range("C10") = ""
            Range("D10") = ""
            Range("F10") = ""
            Range("G10") = ""
        End With
    
    End Sub

    Your routine checks for empty cells, but does not check for cells that contain blanks and no other characters. I added 'MyIsEmpty()' to replace 'IsEmpty()'.

    MyIsEmpty():
    a. Checks for empty cell
    b. Checks for cell that contains only spaces (BLANKS)
    c. Removes leading and trailing spaces from non-BLANK cells

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    
        If MyIsEmpty(ThisWorkbook.Sheets(1).Range("B6")) Then
            MsgBox ("Must enter Supplier Name")
            Cancel = True
            Exit Sub
        End If
        If MyIsEmpty(ThisWorkbook.Sheets(1).Range("C6")) Then
           MsgBox ("Must enter Supplier Location")
           Cancel = True
           Exit Sub
        End If
        If MyIsEmpty(ThisWorkbook.Sheets(1).Range("D6")) Then
           MsgBox ("Please enter your 5 digit supplier code. If you need assistance with the supplier code please contact SSG at 1(800)782-8099")
           Cancel = True
           Exit Sub
        End If
        If MyIsEmpty(ThisWorkbook.Sheets(1).Range("B10")) Then
           MsgBox ("Please enter expected users First name")
           Cancel = True
           Exit Sub
        End If
        If MyIsEmpty(ThisWorkbook.Sheets(1).Range("C10")) Then
           MsgBox ("Please enter expected users Last name")
           Cancel = True
           Exit Sub
        End If
        If MyIsEmpty(ThisWorkbook.Sheets(1).Range("D10")) Then
           MsgBox ("Please Create an original SSO # for this user")
           Cancel = True
           Exit Sub
        End If
        If MyIsEmpty(ThisWorkbook.Sheets(1).Range("F10")) Then
           MsgBox ("Please enter expected users email address.      Note: This must be a complete and existing email address")
           Cancel = True
           Exit Sub
        End If
        If MyIsEmpty(ThisWorkbook.Sheets(1).Range("G10")) Then
           MsgBox ("Please enter expected users full phone number with area code")
           Cancel = True
           Exit Sub
        End If
    End Sub
    
    Private Function MyIsEmpty(ByRef r As Range) As Boolean
      'This returns true if a cell is EMPTY or if the cell contains all blanks
      'This also removes leading and trailing blanks from the cell
    
      Dim s As String
      s = Trim(r.Text)
      
      If IsEmpty(r) Or Len(s) = 0 Then
        MyIsEmpty = True
      Else
        'Remove leading and trailing blanks from the value
        r.Value = Trim(r.Text)
      End If
    End Function
    Lewis

  4. #4
    Registered User
    Join Date
    08-14-2013
    Location
    Kentucky, United States
    MS-Off Ver
    03,07,10
    Posts
    61

    Re: IsBlank function run on form will not allow initial save of bank value to send to user

    Thank you all for the information (Sorry for spelling errors in advance). I did figure out the issue myself. I also concatenated the msgbox to contain all of the errors at once. I created the following code to cover three scenarios:

    1. Will save if all fields are null
    2. Will not save if one or more of the required fields are null
    3. Will save if all fields required are completed.

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    
    If IsEmpty(ThisWorkbook.Sheets(1).Range("B6")) Then
            MsgBox ("Must enter Supplier Name")
            Cancel = True
        Else
        If IsEmpty(ThisWorkbook.Sheets(1).Range("C6")) Then
           MsgBox ("Must enter Supplier Location")
           Cancel = True
        Else
        If IsEmpty(ThisWorkbook.Sheets(1).Range("D6")) Then
           MsgBox ("Please enter your 5 digit supplier code. If you need assistance with the supplier code please contact SSG at 1(800)782-8099")
           Cancel = True
        Else
        If IsEmpty(ThisWorkbook.Sheets(1).Range("B10")) Then
           MsgBox ("Please enter expected users First name")
           Cancel = True
        Else
        If IsEmpty(ThisWorkbook.Sheets(1).Range("C10")) Then
           MsgBox ("Please enter expected users Last name")
           Cancel = True
        Else
        If IsEmpty(ThisWorkbook.Sheets(1).Range("D10")) Then
           MsgBox ("Please Create an original SSO # for this user")
           Cancel = True
        Else
        If IsEmpty(ThisWorkbook.Sheets(1).Range("F10")) Then
           MsgBox ("Please enter expected users email address.      Note: This must be a complete and existing email address")
           Cancel = True
        Else
        If IsEmpty(ThisWorkbook.Sheets(1).Range("G10")) Then
           MsgBox ("Please enter expected users full phone number with area code")
           Cancel = True
    
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    
    End Sub

  5. #5
    Registered User
    Join Date
    08-14-2013
    Location
    Kentucky, United States
    MS-Off Ver
    03,07,10
    Posts
    61

    Re: IsBlank function run on form will not allow initial save of bank value to send to user

    I will definitly change the code to reflect the MyIsEmpty() rather than the IsEmpty(). I can see where this would benifit. Thank you again for the information and the quick responses.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Disable save function for users
    By Barry Engelbrecht in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 07-09-2013, 09:36 AM
  2. Initial Combobox blank value in a Form is Null
    By Paulo Buchsbaum in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-26-2012, 11:50 AM
  3. disable save & send function
    By wetph00t in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-12-2012, 04:24 PM
  4. Help with ISBLANK function referring to a cell with another ISBLANK formula
    By camdameron in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 03-23-2011, 12:45 PM
  5. Form function to save worksheet
    By jcarstens in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-28-2009, 06:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1