Need OnNoData for Forms

  • Thread starter Thread starter Bonnie
  • Start date Start date
B

Bonnie

Hello everyone!!! Using A02 on XP. I use the OnNoData
event in reports to tell a user there is no data to
display and exit the sub without opening the report.
However, I have many Forms that would benefit from this.
As it is, when there is no data, the form opens but with
no data showing at all. Fields are blank. I would like to
have a message box appear and when they click okay, no
empty form to close. How can I code an event when a
frontscreen button is clicked to open a form and that
form will have no data to display? I'd really appreciate
any help or advice offered. Thanks in advance for any
assistance! Love you guys!
 
Try using a DCount() on the source for your form in an If
Then Else structure. If >0 then open form Else cancel
command button.
 
Hi Nick! Thanks oodles for the info. One more question???
Hope you have a thread attached... The form doesn't open
(perfect) but I get a second msgbox saying "the OpenForm
action was cancelled" and I have to click okay again. How
can I get rid of that second message? Here is my wordage:

Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "There are no unbilled Amendment Records
for this contract."
Cancel = True
Exit Sub
End If
End Sub

Thanks for your help!!!
 
Hi Nick! Thanks oodles for the info. One more question???
Hope you have a thread attached... The form doesn't open
(perfect) but I get a second msgbox saying "the OpenForm
action was cancelled" and I have to click okay again. How
can I get rid of that second message? Here is my wordage:

Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "There are no unbilled Amendment Records
for this contract."
Cancel = True
Exit Sub
End If
End Sub

Thanks for your help!!!

Trap the error in the event that originally opened the form (a
switchboard command button click event?).

On Error GoTo Err_Handler
DoCmd.OpenForm "FormName"
Exit_Sub:
Exit Sub
Err_Handler:
If Err = 2501 then
Else
MsgBox "Error #: " & Err.Number & " " & Err.Description
End If
Resume Exit_Sub
 
Bonnie said:
Hello everyone!!! Using A02 on XP. I use the OnNoData
event in reports to tell a user there is no data to
display and exit the sub without opening the report.
However, I have many Forms that would benefit from this.
As it is, when there is no data, the form opens but with
no data showing at all. Fields are blank. I would like to
have a message box appear and when they click okay, no
empty form to close. How can I code an event when a
frontscreen button is clicked to open a form and that
form will have no data to display?


Trap (and ignore) error number 2501 in the code that opens
the form.

Original form's button:

On Error GoTo ErrHandler
DoCmd OpenForm "otherform"
. . .
OutOfHere:
Exit Sub

ErrHandler:
Select Case Err.Number
Case 2501
MsgBox "There are no unbilled Amendment Records for this
contract."
Resume Next
Case Else
MsgBox Err.Number & " - " & Err.Description
Resume OutOfHere
End Select
End Sub

Other form's code

Cancel = (Me.RecordsetClone.RecordCount = 0)
 
Hi Marsh! Thanks very much for the info. It works great.
I had seen it before but couldn't remember where. Thanks
for being such a great contributor to my accumulation of
knowledge! (And of course I was wearing the red shoes on
our last exchange. I had to set that project aside but
I'll get back to it one day.)
 
Hi Marsh! Thanks very much for the info. It works great.
I had seen it before but couldn't remember where. Thanks
for being such a great contributor to my accumulation of
knowledge! (And of course I was wearing the red shoes on
our last exchange. I had to set that project aside but
I'll get back to it one day.)
 
Fred, thanks loads for the wordage. It works great!
Thanks for taking the time to help others!
 
Back
Top