Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 195
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error Handling - On Error GoTo doesn't trap error successfully David Excel Programming 9 February 16th 06 05:59 PM
error handling Pierre via OfficeKB.com[_2_] Excel Programming 0 November 2nd 05 09:19 AM
Error Handling Dave M. Excel Programming 1 August 31st 05 07:15 PM
Error handling with a handling routine ben Excel Programming 0 March 15th 05 03:01 PM
Error handling V. Roe Excel Programming 2 February 27th 04 08:04 PM


All times are GMT +1. The time now is 09:21 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"