Error Procedure running when no error occurs

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Greetings - I have a main table into which data is collected using forms.
From this data I have two reports that are built using a query to "filter"
the data. One query is set to return only those records that have been
identified as "Portfolio" and one that returns only those records identified
as "Project."

I created an error procedure to return an "understandable" error message to
the user instead of the runtime error 2427: You entered an expression that
has no value. The error procedure is returning the understandble message,
however it is doing it consistantly and not just when an actual error has
occured.

Any suggestions on how to fix?

Thanks!
Ember
 
Since the query has filter based on portfolio or project, when the report is
ran it asks for the "File ID". If they are running the portfolio report and
enter a project file id the run-time error occurs...which is fine. However,
I want the users to realize that they have entered an incorrect file id, so
my message states that and when you click on the "OK" button it will take
you to a blank report that can then be closed and re-ran.

Ember
 
Sorry, that doesn't really explain anything to me.

Can you copy-and-paste the relevant code?
 
Here is the code. Please know that the report is ran off of a select query
over which the users have no design control.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
On Error GoTo Err_MyProcedure
If [Series_Code] = "ACC" Then
[Series_Code].BackColor = 8421376
ElseIf [Series_Code] = "COR" Then
[Series_Code].BackColor = 26367
ElseIf [Series_Code] = "DEV" Then
[Series_Code].BackColor = 6697881
ElseIf [Series_Code] = "ENV" Then
[Series_Code].BackColor = 65535
ElseIf [Series_Code] = "FIN" Then
[Series_Code].BackColor = 6723891
ElseIf [Series_Code] = "HR" Then
[Series_Code].BackColor = 13408767
ElseIf [Series_Code] = "INS" Then
[Series_Code].BackColor = 13209
ElseIf [Series_Code] = "LGL" Then
[Series_Code].BackColor = 255
ElseIf [Series_Code] = "MKT" Then
[Series_Code].BackColor = 16711680
ElseIf [Series_Code] = "RES" Then
[Series_Code].BackColor = 16764057
ElseIf [Series_Code] = "COM" Then
[Series_Code].BackColor = 12632256
Else
[Series_Code].BackColor = 16777215

End If

Err_MyProcedure:
Msg = MsgBox("File ID entered not a Portfolio file", vbOKOnly +
vbExclamation)
Select Case Msg
Case vbOK
DoCmd.CancelEvent
End Select
End Sub

Thanks!
Ember
 
YOU FORGOT THE exit sub before ur err statement
lewie said:
Here is the code. Please know that the report is ran off of a select query
over which the users have no design control.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
On Error GoTo Err_MyProcedure
If [Series_Code] = "ACC" Then
[Series_Code].BackColor = 8421376
ElseIf [Series_Code] = "COR" Then
[Series_Code].BackColor = 26367
ElseIf [Series_Code] = "DEV" Then
[Series_Code].BackColor = 6697881
ElseIf [Series_Code] = "ENV" Then
[Series_Code].BackColor = 65535
ElseIf [Series_Code] = "FIN" Then
[Series_Code].BackColor = 6723891
ElseIf [Series_Code] = "HR" Then
[Series_Code].BackColor = 13408767
ElseIf [Series_Code] = "INS" Then
[Series_Code].BackColor = 13209
ElseIf [Series_Code] = "LGL" Then
[Series_Code].BackColor = 255
ElseIf [Series_Code] = "MKT" Then
[Series_Code].BackColor = 16711680
ElseIf [Series_Code] = "RES" Then
[Series_Code].BackColor = 16764057
ElseIf [Series_Code] = "COM" Then
[Series_Code].BackColor = 12632256
Else
[Series_Code].BackColor = 16777215

End If

Err_MyProcedure:
Msg = MsgBox("File ID entered not a Portfolio file", vbOKOnly +
vbExclamation)
Select Case Msg
Case vbOK
DoCmd.CancelEvent
End Select
End Sub

Thanks!
Ember

Douglas J. Steele said:
Sorry, that doesn't really explain anything to me.

Can you copy-and-paste the relevant code?
 
My "End Sub" is in the wrong place?

Ember

lewie said:
YOU FORGOT THE exit sub before ur err statement
lewie said:
Here is the code. Please know that the report is ran off of a select query
over which the users have no design control.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
On Error GoTo Err_MyProcedure
If [Series_Code] = "ACC" Then
[Series_Code].BackColor = 8421376
ElseIf [Series_Code] = "COR" Then
[Series_Code].BackColor = 26367
ElseIf [Series_Code] = "DEV" Then
[Series_Code].BackColor = 6697881
ElseIf [Series_Code] = "ENV" Then
[Series_Code].BackColor = 65535
ElseIf [Series_Code] = "FIN" Then
[Series_Code].BackColor = 6723891
ElseIf [Series_Code] = "HR" Then
[Series_Code].BackColor = 13408767
ElseIf [Series_Code] = "INS" Then
[Series_Code].BackColor = 13209
ElseIf [Series_Code] = "LGL" Then
[Series_Code].BackColor = 255
ElseIf [Series_Code] = "MKT" Then
[Series_Code].BackColor = 16711680
ElseIf [Series_Code] = "RES" Then
[Series_Code].BackColor = 16764057
ElseIf [Series_Code] = "COM" Then
[Series_Code].BackColor = 12632256
Else
[Series_Code].BackColor = 16777215

End If

Err_MyProcedure:
Msg = MsgBox("File ID entered not a Portfolio file", vbOKOnly +
vbExclamation)
Select Case Msg
Case vbOK
DoCmd.CancelEvent
End Select
End Sub

Thanks!
Ember

Douglas J. Steele said:
Sorry, that doesn't really explain anything to me.

Can you copy-and-paste the relevant code?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Since the query has filter based on portfolio or project, when the report
is
ran it asks for the "File ID". If they are running the portfolio report
and
enter a project file id the run-time error occurs...which is fine.
However,
I want the users to realize that they have entered an incorrect file id,
so
my message states that and when you click on the "OK" button it will take
you to a blank report that can then be closed and re-ran.

Ember

:

How did you add your error procedure? What calls it?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Greetings - I have a main table into which data is collected using
forms.
From this data I have two reports that are built using a query to
"filter"
the data. One query is set to return only those records that have been
identified as "Portfolio" and one that returns only those records
identified
as "Project."

I created an error procedure to return an "understandable" error
message
to
the user instead of the runtime error 2427: You entered an expression
that
has no value. The error procedure is returning the understandble
message,
however it is doing it consistantly and not just when an actual error
has
occured.

Any suggestions on how to fix?

Thanks!
Ember
 
No, your End Sub isn't in the wrong place. However, you need to tell Access
to ignore the Error Processing if there isn't an error.

Where you've currently got:

End If

Err_MyProcedure:
Msg = MsgBox("File ID entered not a Portfolio file", vbOKOnly +
vbExclamation)
Select Case Msg
Case vbOK
DoCmd.CancelEvent
End Select
End Sub

put

End If

End_MyProcedure:
Exit Sub

Err_MyProcedure:
Msg = MsgBox("File ID entered not a Portfolio file", vbOKOnly +
vbExclamation)
Select Case Msg
Case vbOK
DoCmd.CancelEvent
End Select
Resume End_MyProcedure

End Sub


(The Resume is a good idea, since it'll reset the Error object so that
Access knows there is no longer an error)

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Ember said:
My "End Sub" is in the wrong place?

Ember

lewie said:
YOU FORGOT THE exit sub before ur err statement
lewie said:
Here is the code. Please know that the report is ran off of a select
query
over which the users have no design control.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
On Error GoTo Err_MyProcedure
If [Series_Code] = "ACC" Then
[Series_Code].BackColor = 8421376
ElseIf [Series_Code] = "COR" Then
[Series_Code].BackColor = 26367
ElseIf [Series_Code] = "DEV" Then
[Series_Code].BackColor = 6697881
ElseIf [Series_Code] = "ENV" Then
[Series_Code].BackColor = 65535
ElseIf [Series_Code] = "FIN" Then
[Series_Code].BackColor = 6723891
ElseIf [Series_Code] = "HR" Then
[Series_Code].BackColor = 13408767
ElseIf [Series_Code] = "INS" Then
[Series_Code].BackColor = 13209
ElseIf [Series_Code] = "LGL" Then
[Series_Code].BackColor = 255
ElseIf [Series_Code] = "MKT" Then
[Series_Code].BackColor = 16711680
ElseIf [Series_Code] = "RES" Then
[Series_Code].BackColor = 16764057
ElseIf [Series_Code] = "COM" Then
[Series_Code].BackColor = 12632256
Else
[Series_Code].BackColor = 16777215

End If

Err_MyProcedure:
Msg = MsgBox("File ID entered not a Portfolio file", vbOKOnly +
vbExclamation)
Select Case Msg
Case vbOK
DoCmd.CancelEvent
End Select
End Sub

Thanks!
Ember

:

Sorry, that doesn't really explain anything to me.

Can you copy-and-paste the relevant code?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Since the query has filter based on portfolio or project, when the
report
is
ran it asks for the "File ID". If they are running the portfolio
report
and
enter a project file id the run-time error occurs...which is fine.
However,
I want the users to realize that they have entered an incorrect
file id,
so
my message states that and when you click on the "OK" button it
will take
you to a blank report that can then be closed and re-ran.

Ember

:

How did you add your error procedure? What calls it?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Greetings - I have a main table into which data is collected
using
forms.
From this data I have two reports that are built using a query
to
"filter"
the data. One query is set to return only those records that
have been
identified as "Portfolio" and one that returns only those
records
identified
as "Project."

I created an error procedure to return an "understandable" error
message
to
the user instead of the runtime error 2427: You entered an
expression
that
has no value. The error procedure is returning the
understandble
message,
however it is doing it consistantly and not just when an actual
error
has
occured.

Any suggestions on how to fix?

Thanks!
Ember
 
Thank you very much. I will see if that works!

Ember

Douglas J. Steele said:
No, your End Sub isn't in the wrong place. However, you need to tell Access
to ignore the Error Processing if there isn't an error.

Where you've currently got:

End If

Err_MyProcedure:
Msg = MsgBox("File ID entered not a Portfolio file", vbOKOnly +
vbExclamation)
Select Case Msg
Case vbOK
DoCmd.CancelEvent
End Select
End Sub

put

End If

End_MyProcedure:
Exit Sub

Err_MyProcedure:
Msg = MsgBox("File ID entered not a Portfolio file", vbOKOnly +
vbExclamation)
Select Case Msg
Case vbOK
DoCmd.CancelEvent
End Select
Resume End_MyProcedure

End Sub


(The Resume is a good idea, since it'll reset the Error object so that
Access knows there is no longer an error)

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Ember said:
My "End Sub" is in the wrong place?

Ember

lewie said:
YOU FORGOT THE exit sub before ur err statement
lewie
Ember wrote:
Here is the code. Please know that the report is ran off of a select
query
over which the users have no design control.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
On Error GoTo Err_MyProcedure
If [Series_Code] = "ACC" Then
[Series_Code].BackColor = 8421376
ElseIf [Series_Code] = "COR" Then
[Series_Code].BackColor = 26367
ElseIf [Series_Code] = "DEV" Then
[Series_Code].BackColor = 6697881
ElseIf [Series_Code] = "ENV" Then
[Series_Code].BackColor = 65535
ElseIf [Series_Code] = "FIN" Then
[Series_Code].BackColor = 6723891
ElseIf [Series_Code] = "HR" Then
[Series_Code].BackColor = 13408767
ElseIf [Series_Code] = "INS" Then
[Series_Code].BackColor = 13209
ElseIf [Series_Code] = "LGL" Then
[Series_Code].BackColor = 255
ElseIf [Series_Code] = "MKT" Then
[Series_Code].BackColor = 16711680
ElseIf [Series_Code] = "RES" Then
[Series_Code].BackColor = 16764057
ElseIf [Series_Code] = "COM" Then
[Series_Code].BackColor = 12632256
Else
[Series_Code].BackColor = 16777215

End If

Err_MyProcedure:
Msg = MsgBox("File ID entered not a Portfolio file", vbOKOnly +
vbExclamation)
Select Case Msg
Case vbOK
DoCmd.CancelEvent
End Select
End Sub

Thanks!
Ember

:

Sorry, that doesn't really explain anything to me.

Can you copy-and-paste the relevant code?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Since the query has filter based on portfolio or project, when the
report
is
ran it asks for the "File ID". If they are running the portfolio
report
and
enter a project file id the run-time error occurs...which is fine.
However,
I want the users to realize that they have entered an incorrect
file id,
so
my message states that and when you click on the "OK" button it
will take
you to a blank report that can then be closed and re-ran.

Ember

:

How did you add your error procedure? What calls it?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Greetings - I have a main table into which data is collected
using
forms.
From this data I have two reports that are built using a query
to
"filter"
the data. One query is set to return only those records that
have been
identified as "Portfolio" and one that returns only those
records
identified
as "Project."

I created an error procedure to return an "understandable" error
message
to
the user instead of the runtime error 2427: You entered an
expression
that
has no value. The error procedure is returning the
understandble
message,
however it is doing it consistantly and not just when an actual
error
has
occured.

Any suggestions on how to fix?

Thanks!
Ember
 
Back
Top