Setting up "No Records Found" Message

  • Thread starter Basil via AccessMonster.com
  • Start date
B

Basil via AccessMonster.com

I have a parameter report that requests the user to enter a specific date,
and then the system returns a list of records for that date. When there are
no records found, the report displays with either "Error" or null data in the
text boxes. I would like to set it up so that the user receives a message
"No Matching Records Found" (as the blank report could be more confusing).

Q1. Is Event Procedure in the Report's Properties/Event for either On No Data
or On Error (not sure which to use) appropriate here?

Q2. When I select "..." to build the Event Procedure, the VB window opens and
then I'm lost because I don't know how to code in VB. Can anyone point me in
the right direction?

Q3. I found the object browser within the VB window. Is this a good place to
start for writing VB code without knowing much about the syntax?
 
F

fredg

I have a parameter report that requests the user to enter a specific date,
and then the system returns a list of records for that date. When there are
no records found, the report displays with either "Error" or null data in the
text boxes. I would like to set it up so that the user receives a message
"No Matching Records Found" (as the blank report could be more confusing).

Q1. Is Event Procedure in the Report's Properties/Event for either On No Data
or On Error (not sure which to use) appropriate here?

Q2. When I select "..." to build the Event Procedure, the VB window opens and
then I'm lost because I don't know how to code in VB. Can anyone point me in
the right direction?

Q3. I found the object browser within the VB window. Is this a good place to
start for writing VB code without knowing much about the syntax?

Q1) You would place your code in the report's OnNoData event.

Display the report's property sheet.
Click on the Event tab.
On the OnNoData line, write:
[Event Procedure]
Click on the little button with 3 dots that appears on that line.
When the code window opens, the cursor will be flashing between 2
already existing lines of code.
Between those 2 lines, write:

MsgBox "There are nor records."
Cancel = True

Exit the procedure.

If there is no data for the report, the message will appear and the
report will not run.

Note: if the report has been opened using code, (i.e. a command button
event), it will generate error 2501.
You will need to trap that error in the event that opened the report.

On Error GoTo Err_Handler
DoCmd.OpenReport "YourReport", acViewPreview

Exit_Sub:
Exit Sub
Err_Handler:
If Err = 2501 Then
Else
MsgBox "Error #: " & Err.Number & " " & Err.Description
End If
Resume Exit_Sub
 
B

Basil via AccessMonster.com

Thanks. I was able to set up the OnNoData MsgBox.

For the Error handling, I went into the Switchboard code (Event to open
report is here), and found that when an invalid entry was entered for Date
Parameter, it hit the following HandleButtonClick_Err code. I added the
second sentance about enter dates in the proper format, but I know this isn't
a great solution. Is there a better way to trap the invalid date entries, or
maybe set up a mask on the parameter?

HandleButtonClick_Err:
' If the action was cancelled by the user for
' some reason, don't display an error message.
' Instead, resume on the next line.
If (Err = conErrDoCmdCancelled) Then
Resume Next
Else
MsgBox "There was an error executing the command. Enter dates in
format 'mm/dd/yyyy'.", vbCritical
Resume HandleButtonClick_Exit
End If
I have a parameter report that requests the user to enter a specific date,
and then the system returns a list of records for that date. When there are
[quoted text clipped - 11 lines]
Q3. I found the object browser within the VB window. Is this a good place to
start for writing VB code without knowing much about the syntax?

Q1) You would place your code in the report's OnNoData event.

Display the report's property sheet.
Click on the Event tab.
On the OnNoData line, write:
[Event Procedure]
Click on the little button with 3 dots that appears on that line.
When the code window opens, the cursor will be flashing between 2
already existing lines of code.
Between those 2 lines, write:

MsgBox "There are nor records."
Cancel = True

Exit the procedure.

If there is no data for the report, the message will appear and the
report will not run.

Note: if the report has been opened using code, (i.e. a command button
event), it will generate error 2501.
You will need to trap that error in the event that opened the report.

On Error GoTo Err_Handler
DoCmd.OpenReport "YourReport", acViewPreview

Exit_Sub:
Exit Sub
Err_Handler:
If Err = 2501 Then
Else
MsgBox "Error #: " & Err.Number & " " & Err.Description
End If
Resume Exit_Sub
 
F

fredg

Thanks. I was able to set up the OnNoData MsgBox.

For the Error handling, I went into the Switchboard code (Event to open
report is here), and found that when an invalid entry was entered for Date
Parameter, it hit the following HandleButtonClick_Err code. I added the
second sentance about enter dates in the proper format, but I know this isn't
a great solution. Is there a better way to trap the invalid date entries, or
maybe set up a mask on the parameter?

HandleButtonClick_Err:
' If the action was cancelled by the user for
' some reason, don't display an error message.
' Instead, resume on the next line.
If (Err = conErrDoCmdCancelled) Then
Resume Next
Else
MsgBox "There was an error executing the command. Enter dates in
format 'mm/dd/yyyy'.", vbCritical
Resume HandleButtonClick_Exit
End If
I have a parameter report that requests the user to enter a specific date,
and then the system returns a list of records for that date. When there are
[quoted text clipped - 11 lines]
Q3. I found the object browser within the VB window. Is this a good place to
start for writing VB code without knowing much about the syntax?

Q1) You would place your code in the report's OnNoData event.

Display the report's property sheet.
Click on the Event tab.
On the OnNoData line, write:
[Event Procedure]
Click on the little button with 3 dots that appears on that line.
When the code window opens, the cursor will be flashing between 2
already existing lines of code.
Between those 2 lines, write:

MsgBox "There are nor records."
Cancel = True

Exit the procedure.

If there is no data for the report, the message will appear and the
report will not run.

Note: if the report has been opened using code, (i.e. a command button
event), it will generate error 2501.
You will need to trap that error in the event that opened the report.

On Error GoTo Err_Handler
DoCmd.OpenReport "YourReport", acViewPreview

Exit_Sub:
Exit Sub
Err_Handler:
If Err = 2501 Then
Else
MsgBox "Error #: " & Err.Number & " " & Err.Description
End If
Resume Exit_Sub

If you need to check for correctly entered dates, create an unbound
form to enter the dates in. Then you can use an event on the form to
verify that the dates are correctly entered. You can't do that on the
switchboard. If you need help with using an unbound form to enter
report parameters into, search www.groups.google.com or post back.

The problem with the built-in switchboard is that it is not very
adaptable. It may be quick for a non-experienced user to set up, but
it works the way it works, which is not necessarily the way you want
it to work. It has been said by an experienced poster here that the
built-in switchboard is a complicated solution to a simple problem.

It would be better to create your own switchboard, using an unbound
form and command buttons. You will have more control over it's
appearance and functionality. Maintenance will be much easier. You'll
be happier. :)
 
B

Basil via AccessMonster.com

Thank you! I'll look into creating my own switchboards and using unbound
forms.
Thanks. I was able to set up the OnNoData MsgBox.
[quoted text clipped - 57 lines]
If you need to check for correctly entered dates, create an unbound
form to enter the dates in. Then you can use an event on the form to
verify that the dates are correctly entered. You can't do that on the
switchboard. If you need help with using an unbound form to enter
report parameters into, search www.groups.google.com or post back.

The problem with the built-in switchboard is that it is not very
adaptable. It may be quick for a non-experienced user to set up, but
it works the way it works, which is not necessarily the way you want
it to work. It has been said by an experienced poster here that the
built-in switchboard is a complicated solution to a simple problem.

It would be better to create your own switchboard, using an unbound
form and command buttons. You will have more control over it's
appearance and functionality. Maintenance will be much easier. You'll
be happier. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top