Archive for May, 2009

Prevent opening a report if no data to show

Wednesday, May 20th, 2009

We can prevent a report open if no data to show, and for this we use two forms depending on the version of Access:

1 - All versions of ACCESS
Place the code below in the properties of the report, the event 'Enabling'

Use the event Enabling (Activate) Report:

Private Sub Report_Activate ()

If DCount ("*", Me.RecordSource) = 0 Then

MsgBox "No records to display" vbDefaultButton1, "Error!"

AcReport DoCmd.Close, "report name"

End If

End Sub

2 - From version 7 (Access 95) was added the event 'if no data', then we can urilizar the following code:

Private Sub Report_NoData (Cancel As Integer)

MsgBox "No data in the report.", VbInformation, "Error!"

Cancel = True

End Sub

To see running download the example: Prevent opening report

How to prevent a form open if no records to show?

Saturday, May 2nd, 2009

Sometimes it is necessary to prevent a form open if there are records to show, for example when doing a query and no registration is not required, we do not need to be open form since we have no data to display. So what we have to check is whether there are records to show and if there is no show a message and impede the form open. How?

It's easy to just put the code below in the form properties in the event 'to open':

= 0 Then If Form.RecordsetClone.RecordCount
MsgBox "No records found.", VbExclamation, "Error!"
DoCmd.Close acForm, "find data"
Exit Sub
End If

To see an example download: Prevent Form Open

Presentation

Avatar

Thank you for visiting.
Subscribe to feed not to miss any messages.

Here in blog I will provide examples of working with Microsoft Access and also ask questions to those who ask. More

Want to subscribe?

Subscribe or subscribe by email:
Enter your email:


Ads