G
Greg Maxey
Despite reading the help file until my eyes are blurry, I still can't get my
head around Error Handling.
I have some code provided below that can cause an error if the user inputs
and incorrect format. I would appreciate any feedback regarding the Error
Handling that I have used. While it appears to work, I am not sure if I
have left a door open somewhere that would incude other errors for fail to
detect other errors.
Thanks.
Dim myDate As Date
Dim seqNum As Long
Dim seqLength As Long
Dim seqInt As Long
Dim upSeq As Long
Dim i As Long
Dim dateFormat As String
Retry:
On Error GoTo Oops
myDate = InputBox("Enter the start date in 1/31/05 format.", _
"Start On", Date)
seqLength = InputBox("Enter the sequence length e.g., 14.", _
"Sequence Length", "14")
dateFormat = InputBox("Enter the format for the date display e.g." _
& "dddd, mmm dd yyyy.", "Date Format", "mmmm dd, yyyy")
seqInt = InputBox("Enter the sequence interval.", "Interval", "1")
For seqNum = 1 To seqLength
upSeq = seqNum * seqInt
ActiveDocument.Variables("Var" & seqNum).Value = _
Format(myDate + upSeq - seqInt, dateFormat)
Next
ActiveDocument.Fields.Update
Exit Sub
Oops:
If Err.Number = 13 Then
If MsgBox("Invalid format! Start date must be in 1/31/2005 format", _
vbRetryCancel, "Alert") = vbRetry Then
Resume Retry
End If
Resume Next
End If
End Sub
head around Error Handling.
I have some code provided below that can cause an error if the user inputs
and incorrect format. I would appreciate any feedback regarding the Error
Handling that I have used. While it appears to work, I am not sure if I
have left a door open somewhere that would incude other errors for fail to
detect other errors.
Thanks.
Dim myDate As Date
Dim seqNum As Long
Dim seqLength As Long
Dim seqInt As Long
Dim upSeq As Long
Dim i As Long
Dim dateFormat As String
Retry:
On Error GoTo Oops
myDate = InputBox("Enter the start date in 1/31/05 format.", _
"Start On", Date)
seqLength = InputBox("Enter the sequence length e.g., 14.", _
"Sequence Length", "14")
dateFormat = InputBox("Enter the format for the date display e.g." _
& "dddd, mmm dd yyyy.", "Date Format", "mmmm dd, yyyy")
seqInt = InputBox("Enter the sequence interval.", "Interval", "1")
For seqNum = 1 To seqLength
upSeq = seqNum * seqInt
ActiveDocument.Variables("Var" & seqNum).Value = _
Format(myDate + upSeq - seqInt, dateFormat)
Next
ActiveDocument.Fields.Update
Exit Sub
Oops:
If Err.Number = 13 Then
If MsgBox("Invalid format! Start date must be in 1/31/2005 format", _
vbRetryCancel, "Alert") = vbRetry Then
Resume Retry
End If
Resume Next
End If
End Sub