how can i close a report when there is no table. In a report i use
some VBA code. When i start the report i want to check if the data
table exists. When the table doesn't exits i want the report to be
closed.
i have use the following vba
---
Private Sub Report_Error(DataErr As Integer, Response As Integer)
MsgBox "there is no data first execute the data run"
DoCmd.Close
End Sub
---
when the vba is executed the message box will appear but the report
won't be closed. after klik on Ok. what can i do to close the report?
i have used
---
docmd.close acreport, rpt_reportname
---
but that doesn't work
please your suggestions
|
|
0
|
|
|
|
Reply
|
erikvanmeulen (1)
|
2/25/2010 9:21:12 AM |
|
Erik Meulen wrote:
> how can i close a report when there is no table. In a report i use
> some VBA code. When i start the report i want to check if the data
> table exists. When the table doesn't exits i want the report to be
> closed.
>
> i have use the following vba
>
> ---
> Private Sub Report_Error(DataErr As Integer, Response As Integer)
>
> MsgBox "there is no data first execute the data run"
> DoCmd.Close
>
> End Sub
> ---
>
> when the vba is executed the message box will appear but the report
> won't be closed. after klik on Ok. what can i do to close the report?
>
> i have used
>
> ---
> docmd.close acreport, rpt_reportname
> ---
> but that doesn't work
>
> please your suggestions
Private Sub Report_NoData(Cancel As Integer)
MsgBox "Nothing here"
Cancel = True
End Sub
|
|
0
|
|
|
|
Reply
|
Salad
|
2/25/2010 10:51:46 AM
|
|
Salad wrote:
> Private Sub Report_NoData(Cancel As Integer)
> MsgBox "Nothing here"
> Cancel = True
> End Sub
This works, but you'll get a runtime-error because the OpenRecort action
is stopped.
You'll have to catch this runtime-error to get around this.
Volker
--
Wenn es vom Himmel Zitronen regnet -- lerne, Limonade zu machen.
|
|
0
|
|
|
|
Reply
|
Volker
|
2/25/2010 11:39:04 AM
|
|
Volker Neurath <neanderix@expires-28-02-2010.news-group.org> wrote
in news:1267097944.16@neanderix.newsoffice.de:
> Salad wrote:
>
>> Private Sub Report_NoData(Cancel As Integer)
>> MsgBox "Nothing here"
>> Cancel = True
>> End Sub
>
> This works, but you'll get a runtime-error because the OpenRecort
> action is stopped.
>
> You'll have to catch this runtime-error to get around this.
It's quite easy to write a wrapper function with error handling for
No Data that you can use instead of the direct DoCmd.OpenReport
command.
--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
|
|
0
|
|
|
|
Reply
|
David
|
2/25/2010 5:12:15 PM
|
|
On Feb 25, 4:21 am, Erik Meulen <erikvanmeu...@gmail.com> wrote:
> how can i close a report when there is no table. In a report i use
> some VBA code. When i start the report i want to check if the data
> table exists. When the table doesn't exits i want the report to be
> closed.
>
> i have use the following vba
>
> ---
> Private Sub Report_Error(DataErr As Integer, Response As Integer)
>
> MsgBox "there is no data first execute the data run"
> DoCmd.Close
>
> End Sub
> ---
>
> when the vba is executed the message box will appear but the report
> won't be closed. after klik on Ok. what can i do to close the report?
>
> i have used
>
> ---
> docmd.close acreport, rpt_reportname
> ---
> but that doesn't work
>
> please your suggestions
I like to see if there's any data before opening the report. If you
use a form to open the report, try:
'-----Begin Module Code-----
Public Function DHasRecords(strSQL As String) As Boolean
Dim MyDB As Database
Dim CountRS As Recordset
DHasRecords = False
Set MyDB = CurrentDb
Set CountRS = MyDB.OpenRecordset(strSQL, dbOpenSnapshot)
If CountRS.RecordCount > 0 Then
DHasRecords = True
End If
CountRS.Close
Set CountRS = Nothing
Set MyDB = Nothing
End Function
Public Function DNoRecords(strSQL As String) As Boolean
Dim MyDB As Database
Dim CountRS As Recordset
DNoRecords = True
Set MyDB = CurrentDb
Set CountRS = MyDB.OpenRecordset(strSQL, dbOpenSnapshot)
If CountRS.RecordCount > 0 Then
DNoRecords = False
End If
CountRS.Close
Set CountRS = Nothing
Set MyDB = Nothing
End Function
'-----End Module Code-----
Sample:
Suppose the RecordSource for the report is:
SELECT Field1 As A, Field2 As B, Field3 As C From Table1 WHERE Field1
< 20;
'-----Code behind Form-----
strSQL = "SELECT * FROM Table1 WHERE Field1 < 20;"
If DHasRecords(strSQL) Then
DoCmd.OpenReport "rptTest", acViewPreview
Else
MsgBox("No records satisfy the criteria/criterion.")
End
'-----End Code behind Form-----
If you don't use a form to open the report, the test can be made in
the report's Open event. A Cancel there should work as expected.
Something like:
Private Sub Report_Open(Cancel As Integer)
Dim strSQL As String
strSQL = "SELECT * FROM Table1 WHERE Field1 < 20;"
If DNoRecords(strSQL) Then
MsgBox ("No records satisfy the criteria/criterion.")
Cancel = True
Exit Sub
End If
'...
End Sub
End If
James A. Fortune
CDMAPoster@FortuneJames.com
|
|
0
|
|
|
|
Reply
|
James
|
2/25/2010 6:35:21 PM
|
|
Hi David,
David W. Fenton wrote:
> Volker Neurath <neanderix@expires-28-02-2010.news-group.org> wrote
> in news:1267097944.16@neanderix.newsoffice.de:
>> Salad wrote:
>>
>>> Private Sub Report_NoData(Cancel As Integer)
>>> MsgBox "Nothing here"
>>> Cancel = True
>>> End Sub
>>
>> This works, but you'll get a runtime-error because the OpenRecort
>> action is stopped.
>>
>> You'll have to catch this runtime-error to get around this.
> It's quite easy to write a wrapper function with error handling for
> No Data that you can use instead of the direct DoCmd.OpenReport
> command.
My post was just meant to be an information - to prevent the
threadstarter from wondering why getting a runtime-error.
Of course it is quite easy to get around it (I assume, the report is
opened via button-click):
private sub cmdMyReport_click()
On Error GoTo ErrLeer
DoCmd.OpenReport "Berichtsname"
ErrLeer:
If Err.Number = 2501 Then Exit Sub
end sub
Private Sub Report_NoData(Cancel As Integer)
MsgBox "Nothing here"
Cancel = True
End Sub
--
Wenn es vom Himmel Zitronen regnet -- lerne, Limonade zu machen.
|
|
0
|
|
|
|
Reply
|
Volker
|
2/26/2010 10:00:49 AM
|
|
|
5 Replies
407 Views
(page loaded in 0.287 seconds)
Similiar Articles: close report, no data - comp.databases.ms-accesshow can i close a report when there is no table. In a report i use some VBA code. When i start the report i want to check if the data table exists. ... Headers In Multiple Column Reports - And Hiding On No data - comp ...close report, no data - comp.databases.ms-access Headers In Multiple Column Reports - And Hiding On No data - comp ... close report, no data - comp.databases.ms-access ... Re: Mock ups (a sample of ods report writing interface) - comp ...close report, no data - comp.databases.ms-access Re: Mock ups (a sample of ods report writing interface) - comp ... Here is a sample how you can make a typical demo mock ... Report Generator - comp.lang.awkclose report, no data - comp.databases.ms-access Report Generator - comp.lang.awk It was meant to be used at the end of a pipeline that created the data, then be sent to a ... Re: Creating one report with columns based on different subsets ...close report, no data - comp.databases.ms-access Re: Creating one report with columns based on different subsets ... close report, no data - comp.databases.ms-access ... Matlab crashes on image/surf - comp.soft-sys.matlabclose report, no data - comp.databases.ms-access Matlab crashes on image/surf - comp.soft-sys.matlab close report, no data - comp.databases.ms-access Matlab crashes on ... Re: Printing Multiple Reports From a Recordset - comp.databases.ms ...close report, no data - comp.databases.ms-access Re: Creating one report with columns based on different subsets ... close report ... Multiple Reports From Recordset ... prevent direct access to JSP - comp.lang.java.programmer ...Okay, so we're upgrading to Tomcat 6, and we've encountered a difficulty. In order to keep URLs consistent (for simpler log parsing and for cosmetic... PROC REPORT events for use with tagsets - comp.soft-sys.sas ...... 2, that same text has now become a data_note event, so our tagset no ... run; ods tagsets.supermap close ... all' doc='help'); > > >proc report data=sashelp ... Translate from TCP to X.25 - comp.dcom.sys.cisco... X25 call is rejected TCP connection establishment will report an ... happens in step 4 if there is an > error in sending X.25 data packets, will the TCP end be notified. No ... Reports: Close report automatically if no data found© 1998-2010, Dev Ashish & Arvin Meyer, All rights reserved. Optimized for Microsoft Internet Explorer close report, no data - comp.databases.ms-access | Computer Grouphow can i close a report when there is no table. In a report i use some VBA code. When i start the report i want to check if the data table exists. ... 7/28/2012 3:46:53 AM
|