Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
error handling date
I am trying to get the proper error messages to display if the user left a
date field blank or did not put the date in proper format. I have the cell formatted to short date and it shows the date in the proper format. Right now when leave blank getting format error msg instead of blank error message. any ideas? Sub Verify_FPP_Info() On Error GoTo Handler Dim x As Integer PName = Sheets("Program Controls").Range("F4").Value RCID = Sheets("Program Controls").Range("F6").Value BPrd = Sheets("Program Controls").Range("F8").Value EPrd = Sheets("Program Controls").Range("F10").Value AName = Sheets("Program Controls").Range("F12").Value If PName = "" Then x = MsgBox("You must enter a Participant Name", vbCritical, "Error") Range("ParticipantName").Select Range("ParticipantName").Activate End ElseIf RCID = "" Then x = MsgBox("You must enter Participant's ID", vbCritical, "Error") Range("ParticipantID").Select Range("ParticipantID").Activate End ElseIf BPrd = "" Then x = MsgBox("You must enter Period From Date", vbCritical, "Error") Range("PeriodFrom").Select Range("PeriodFrom").Activate End ElseIf EPrd = "" Then '*****starting here x = MsgBox("You must enter a Period Thru Date", vbCritical, "Error") Range("PeriodThru").Select Range("PeriodThru").Activate End ElseIf BPrd EPrd Then x = MsgBox("The Thru Date must be after the From Date", vbCritical, "Error") Range("PeriodThru").Select Range("PeriodThru").Activate End ElseIf AName = "" Then x = MsgBox("You must enter an Auditor's Name", vbCritical, "Error") Range("Auditor").Select Range("Auditor").Activate End End If Exit Sub Handler: 'Get here means failure Select Case Err.Number Case 13 x = MsgBox("Make sure your dates are in the right format MM/DD/YY", vbCritical, "Error") Range("PeriodFrom").Select Range("PeriodFrom").Activate End Case Else Dim Msg As String Msg = Err.Number & ":" & Err.Description MsgBox Msg End End Select End Sub |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
error handling date
If the error message is 1004 like I got when I tested this
try this errorhandler.. ( Is this what you are trying to achieve????) Select Case Err.Number Case 13 x = MsgBox("Make sure your dates are in the right format MM/DD/YY", vbCritical, "Error") Range("PeriodFrom").Select Range("PeriodFrom").Activate End Case 1004 x = MsgBox("Make sure your dates are in the right format MM/DD/YY", vbCritical, "Error") Case Else Dim Msg As String Msg = Err.Number & ":" & Err.Description MsgBox Msg End Select End Sub Arnold Klapheck wrote: I am trying to get the proper error messages to display if the user left a date field blank or did not put the date in proper format. I have the cell formatted to short date and it shows the date in the proper format. Right now when leave blank getting format error msg instead of blank error message. any ideas? Sub Verify_FPP_Info() On Error GoTo Handler Dim x As Integer PName = Sheets("Program Controls").Range("F4").Value RCID = Sheets("Program Controls").Range("F6").Value BPrd = Sheets("Program Controls").Range("F8").Value EPrd = Sheets("Program Controls").Range("F10").Value AName = Sheets("Program Controls").Range("F12").Value If PName = "" Then x = MsgBox("You must enter a Participant Name", vbCritical, "Error") Range("ParticipantName").Select Range("ParticipantName").Activate End ElseIf RCID = "" Then x = MsgBox("You must enter Participant's ID", vbCritical, "Error") Range("ParticipantID").Select Range("ParticipantID").Activate End ElseIf BPrd = "" Then x = MsgBox("You must enter Period From Date", vbCritical, "Error") Range("PeriodFrom").Select Range("PeriodFrom").Activate End ElseIf EPrd = "" Then '*****starting here x = MsgBox("You must enter a Period Thru Date", vbCritical, "Error") Range("PeriodThru").Select Range("PeriodThru").Activate End ElseIf BPrd EPrd Then x = MsgBox("The Thru Date must be after the From Date", vbCritical, "Error") Range("PeriodThru").Select Range("PeriodThru").Activate End ElseIf AName = "" Then x = MsgBox("You must enter an Auditor's Name", vbCritical, "Error") Range("Auditor").Select Range("Auditor").Activate End End If Exit Sub Handler: 'Get here means failure Select Case Err.Number Case 13 x = MsgBox("Make sure your dates are in the right format MM/DD/YY", vbCritical, "Error") Range("PeriodFrom").Select Range("PeriodFrom").Activate End Case Else Dim Msg As String Msg = Err.Number & ":" & Err.Description MsgBox Msg End End Select End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Error Handling - On Error GoTo doesn't trap error successfully | Excel Programming | |||
error handling | Excel Programming | |||
Error Handling | Excel Programming | |||
Error handling with a handling routine | Excel Programming | |||
Error handling | Excel Programming |