I have a userform that upon opening the 'Master' file, it will rename the file once you fill out the userform with a name that comes from the Event name (Userform textbox). The issue that I will have is that if someone uses 1 of the 9 characters that you cannot use, I have an error handler that does not allow you to save.... I would rather them not be able to continue on the userform until they have correctly named their event.
Below is the button click for submitting the data. I think that the validation should be included with "Me.TextBoxE_EventName.Value"... any ideas of what I could put in there?
Private Sub CommandButton_ECancelREV_Click()
'----------------------------------------------------
'Check Validation of Completed form
'----------------------------------------------------
If Trim(Me.TextBoxE_RequestBy.Value) = "" Then
Me.TextBoxE_RequestBy.SetFocus
MsgBox "Please fill in 'Request By' before canceling form", vbCritical
Exit Sub
End If
If Trim(Me.TextBoxE_OnSiteContact.Value) = "" Then
Me.TextBoxE_OnSiteContact.SetFocus
MsgBox "Please fill in 'On Site Contact' before canceling form", vbCritical
Exit Sub
End If
If Trim(Me.TextBoxE_OnSiteNumber.Value) = "" Then
Me.TextBoxE_OnSiteNumber.SetFocus
MsgBox "Please fill in 'On Site Phone Number' before canceling form"
Exit Sub
End If
If Trim(Me.TextBoxE_EventName.Value) = "" Then
Me.TextBoxE_EventName.SetFocus
MsgBox "Please fill in 'Event Name' before canceling form"
Exit Sub
End If
If Trim(Me.ComboBoxE_LocationNumber.ListIndex) = -1 Then
Me.ComboBoxE_LocationNumber.SetFocus
MsgBox "Please fill in 'Location Number' before canceling form"
Exit Sub
End If
If Trim(Me.ListBoxE_OffSiteDelivery.ListIndex) = -1 Then
Me.ListBoxE_OffSiteDelivery.SetFocus
MsgBox "Please fill in 'Off Site Delivery?' before canceling form"
Exit Sub
End If
If Trim(Me.ListBoxE_RequestStatus.ListIndex) = -1 Then
Me.ListBoxE_RequestStatus.SetFocus
MsgBox "Please fill in 'Request Status' before canceling form"
Exit Sub
End If
If Trim(Me.TextBoxE_DeliverDate.Value) = "" Then
Me.TextBoxE_DeliverDate.SetFocus
MsgBox "Please fill in 'Delivery Date' before canceling form"
Exit Sub
End If
If Trim(Me.ListBoxE_DeliverTime.ListIndex) = -1 Then
Me.ListBoxE_DeliverTime.SetFocus
MsgBox "Please fill in 'Delivery Time' before canceling form"
Exit Sub
End If
If Trim(Me.TextBoxE_SSDate.Value) = "" Then
Me.TextBoxE_SSDate.SetFocus
MsgBox "Please fill in 'Show Start Date' before canceling form"
Exit Sub
End If
If Trim(Me.ListBoxE_SSTime.ListIndex) = -1 Then
Me.ListBoxE_SSTime.SetFocus
MsgBox "Please fill in 'Show Start Time' before canceling form"
Exit Sub
End If
If Trim(Me.TextBoxE_SEDate.Value) = "" Then
Me.TextBoxE_SEDate.SetFocus
MsgBox "Please fill in 'Show End Date' before canceling form"
Exit Sub
End If
If Trim(Me.ListBoxE_SETime.ListIndex) = -1 Then
Me.ListBoxE_SETime.SetFocus
MsgBox "Please fill in 'Show End Time' before canceling form"
Exit Sub
End If
If Trim(Me.TextBoxE_PickupDate.Value) = "" Then
Me.TextBoxE_PickupDate.SetFocus
MsgBox "Please fill in 'Pickup Date' before canceling form"
Exit Sub
End If
If Trim(Me.ListBoxE_PickupTime.ListIndex) = -1 Then
Me.ListBoxE_PickupTime.SetFocus
MsgBox "Please fill in 'Pickup Time' before canceling form"
Exit Sub
End If
Me.Hide
ThisWorkbook.Sheets("Equipment Request").Visible = True
ThisWorkbook.Sheets("Equipment Request").Select
End Sub
Private Sub E_EnterInformation_Click()
'----------------------------------------------------
'Check Validation of Completed form
'----------------------------------------------------
If Trim(Me.TextBoxE_RequestBy.Value) = "" Then
Me.TextBoxE_RequestBy.SetFocus
MsgBox "Please fill in 'Request By' on form", vbCritical
Exit Sub
End If
If Trim(Me.TextBoxE_OnSiteContact.Value) = "" Then
Me.TextBoxE_OnSiteContact.SetFocus
MsgBox "Please fill in 'On Site Contact' on form", vbCritical
Exit Sub
End If
If Trim(Me.TextBoxE_OnSiteNumber.Value) = "" Then
Me.TextBoxE_OnSiteNumber.SetFocus
MsgBox "Please fill in 'On Site Phone Number' on form"
Exit Sub
End If
If Trim(Me.TextBoxE_EventName.Value) = "" Then
Me.TextBoxE_EventName.SetFocus
MsgBox "Please fill in 'Event Name' on form"
Exit Sub
End If
If Trim(Me.ComboBoxE_LocationNumber.ListIndex) = -1 Then
Me.ComboBoxE_LocationNumber.SetFocus
MsgBox "Please fill in 'Location Number' on form"
Exit Sub
End If
If Trim(Me.ListBoxE_OffSiteDelivery.ListIndex) = -1 Then
Me.ListBoxE_OffSiteDelivery.SetFocus
MsgBox "Please fill in 'Off Site Delivery?' on form"
Exit Sub
End If
If Trim(Me.ListBoxE_RequestStatus.ListIndex) = -1 Then
Me.ListBoxE_RequestStatus.SetFocus
MsgBox "Please fill in 'Request Status' on form"
Exit Sub
End If
If Trim(Me.TextBoxE_DeliverDate.Value) = "" Then
Me.TextBoxE_DeliverDate.SetFocus
MsgBox "Please fill in 'Delivery Date' on form"
Exit Sub
End If
If Trim(Me.ListBoxE_DeliverTime.ListIndex) = -1 Then
Me.ListBoxE_DeliverTime.SetFocus
MsgBox "Please fill in 'Delivery Time' on form"
Exit Sub
End If
If Trim(Me.TextBoxE_SSDate.Value) = "" Then
Me.TextBoxE_SSDate.SetFocus
MsgBox "Please fill in 'Show Start Date' on form"
Exit Sub
End If
If Trim(Me.ListBoxE_SSTime.ListIndex) = -1 Then
Me.ListBoxE_SSTime.SetFocus
MsgBox "Please fill in 'Show Start Time' on form"
Exit Sub
End If
If Trim(Me.TextBoxE_SEDate.Value) = "" Then
Me.TextBoxE_SEDate.SetFocus
MsgBox "Please fill in 'Show End Date' on form"
Exit Sub
End If
If Trim(Me.ListBoxE_SETime.ListIndex) = -1 Then
Me.ListBoxE_SETime.SetFocus
MsgBox "Please fill in 'Show End Time' on form"
Exit Sub
End If
If Trim(Me.TextBoxE_PickupDate.Value) = "" Then
Me.TextBoxE_PickupDate.SetFocus
MsgBox "Please fill in 'Pickup Date' on form"
Exit Sub
End If
If Trim(Me.ListBoxE_PickupTime.ListIndex) = -1 Then
Me.ListBoxE_PickupTime.SetFocus
MsgBox "Please fill in 'Pickup Time' on form"
Exit Sub
End If
'Hide or show offsite and order number boxes
If Me.ListBoxE_OffSiteDelivery.Value = "Yes" Then
Me.LabelE_OffSiteAdd.Visible = True
Me.TextBoxE_OffSiteAdd.Visible = True
Else
EquipmentRequest.LabelE_OffSiteAdd.Visible = False
EquipmentRequest.TextBoxE_OffSiteAdd.Visible = False
End If
If Me.ListBoxE_OffSiteDelivery.Value = "Yes" And Me.TextBoxE_OffSiteAdd.Value = "" Then
Me.TextBoxE_OffSiteAdd.SetFocus
MsgBox "Please fill in 'Enter Off Site Location Name and Address' on form"
Exit Sub
End If
If Me.ListBoxE_RequestStatus.Value <> "New" Then
EquipmentRequest.LabelE_OrderNum.Visible = True
EquipmentRequest.TextBoxE_OrderNum.Visible = True
Else
EquipmentRequest.LabelE_OrderNum.Visible = False
EquipmentRequest.TextBoxE_OrderNum.Visible = False
End If
If Me.ListBoxE_RequestStatus.Value <> "New" And Me.TextBoxE_OrderNum.Value = "" Then
Me.TextBoxE_OrderNum.SetFocus
MsgBox "Please fill in 'Enter Order/Job #' on form"
Exit Sub
End If
'--------------------------------------------
'Enter Data in Form
'--------------------------------------------
Call UnProtectAllWorksheets
Sheets("Equipment Request").Range("C6") = Me.TextBoxE_RequestBy.Value 'Name of Requester
Sheets("Equipment Request").Range("C7") = Me.TextBoxE_OnSiteContact.Value 'Name of Contact
Sheets("Equipment Request").Range("C8") = Me.TextBoxE_OnSiteNumber.Value 'Phone Number format
Sheets("Equipment Request").Range("F11") = Me.TextBoxE_Comments.Value 'Comments (not required)
Sheets("Equipment Request").Range("I6") = Me.TextBoxE_EventName.Value 'Name of Event
Sheets("Equipment Request").Range("P24") = Me.ComboBoxE_LocationNumber.Value 'Location Number
Sheets("Equipment Request").Range("I8") = Me.ListBoxE_OffSiteDelivery.Value 'Yes or No Selection
Sheets("Equipment Request").Range("I9") = Me.ListBoxE_RequestStatus.Value 'New or revision or cancel selection
Sheets("Equipment Request").Range("C9") = Me.TextBoxE_PWDate.Value 'Short Date Format
Sheets("Equipment Request").Range("D9") = Me.ListBoxE_PWTime.Value 'Time Format
Sheets("Equipment Request").Range("C10") = Me.TextBoxE_DeliverDate.Value 'Short Date Format
Sheets("Equipment Request").Range("D10") = Me.ListBoxE_DeliverTime.Value 'Time Format
Sheets("Equipment Request").Range("C11") = Me.TextBoxE_SSDate.Value 'Short Date Format
Sheets("Equipment Request").Range("D11") = Me.ListBoxE_SSTime.Value 'Time Format
Sheets("Equipment Request").Range("C12") = Me.TextBoxE_SEDate.Value 'Short Date Format
Sheets("Equipment Request").Range("D12") = Me.ListBoxE_SETime.Value 'Time Format
Sheets("Equipment Request").Range("C13") = Me.TextBoxE_PickupDate.Value 'Short Date Format
Sheets("Equipment Request").Range("D13") = Me.ListBoxE_PickupTime.Value 'Time Format
Sheets("Equipment Request").Range("K8") = Me.TextBoxE_OffSiteAdd.Value 'Address of Offsite
Sheets("Equipment Request").Range("M9") = Me.TextBoxE_OrderNum.Value 'Order/Job # if revision
Sheets("Equipment Request").Range("D5") = Me.TextBoxE_CCEmails.Value
Call ProtectAllWorksheets
Me.Hide
Call ESaveBook
If Sheets("Equipment Request").Range("I9") <> "New" And Sheets("Equipment Request").Range("I9") <> "Dates Revision" And Sheets("Equipment Request").Range("I9") <> "Cancellation Revision" Then
ThisWorkbook.Sheets("Revised Equipment Request").Visible = True
ThisWorkbook.Sheets("Revised Equipment Request").Select
Else
ThisWorkbook.Sheets("Equipment Request").Visible = True
ThisWorkbook.Sheets("Equipment Request").Select
End If
End Sub
I think this should be a nested if statement, I just need some help on where and maybe a good way to do it. Any help would be appreciated.
Below is the "ESaveBook" macro that has the error handler:
Sub ESaveBook()
'----------------------------------------------------
'Save File to Hard Drive For First Time
'----------------------------------------------------
'Call UnProtectAllWorksheets
Application.DisplayAlerts = False
Dim sFile As String
Dim sPath As String
Dim sPS As String
sPS = Application.PathSeparator
sPath = Environ("UserProfile") & sPS & "Documents" & sPS & "!ERF!" & sPS & Format(Sheets("Equipment Request").Range("C10").Value, "mm.dd.yy") & " - " & Format(Sheets("Equipment Request").Range("C13").Value, "mm.dd.yy") & " " & Sheets("Equipment Request").Range("I6").Value & sPS
CreateDirectory sPath
If Len(Dir(sPath, vbDirectory)) = 0 Then Exit Sub 'Couldn't create the path due to invalid or inaccessible location
sFile = Sheets("Equipment Request").Range("I6").Value & " ERF SAVED " & " " & Format(Date, "mm.dd.yy") & " " & Sheets("Equipment Request").Range("I9").Value & ".xlsm"
ActiveWorkbook.SaveAs Filename:=sPath & sFile, FileFormat:=52
MsgBox ("This file has been saved at 'Documents\!ERF!\") & Format(Sheets("Equipment Request").Range("C10").Value, "mm.dd.yy") & " - " & Format(Sheets("Equipment Request").Range("C13").Value, "mm.dd.yy") & " " & Sheets("Equipment Request").Range("I6").Value & ("'. The file name is '") & sFile & ("'. Please do not move target location of file.")
Application.DisplayAlerts = True
'Call ProtectAllWorksheets
End Sub
Sub CreateDirectory(ByVal arg_sFolderpath As String)
If Len(Dir(arg_sFolderpath, vbDirectory)) = 0 Then
Dim sPS As String
sPS = Application.PathSeparator
Dim sBuildPath As String
Dim vFolder As Variant
For Each vFolder In Split(arg_sFolderpath, sPS)
If Len(vFolder) > 0 Then
If Len(sBuildPath) = 0 Then sBuildPath = vFolder Else sBuildPath = sBuildPath & sPS & vFolder
If Len(Dir(sBuildPath, vbDirectory)) = 0 Then
On Error Resume Next
MkDir sBuildPath
On Error GoTo 0
If Len(Dir(sBuildPath, vbDirectory)) = 0 Then
MsgBox "[" & sBuildPath & "] is either invalid or unreachable.", , "Create Directory Error"
Exit Sub
End If
End If
End If
Next vFolder
End If
End Sub