Close form after opening report. 
Author Message
 Close form after opening report.

Is there a way to have a report close the form that opens
the report?

TIA,
     Jeff R



Mon, 14 Feb 2005 02:50:22 GMT  
 Close form after opening report.
If the report is always opened from the same form, it's very easy -
DoCmd.Close acForm, "NameOfFormHere"

If the report can be opened by more than one form, it get's a bit more
complicated. One approach would be to have code in the form put it's name
into a global variable, and have the report get the form name from there.

In Access 2002, the OpenReport method has an OpenArgs argument that you
could use to pass the name of the form.

--
Brendan Reynolds (MVP)

Access 2000/2002 sample app at
http://brenreyn.brinkster.net
----------------------------

Quote:
> Is there a way to have a report close the form that opens
> the report?

> TIA,
>      Jeff R



Mon, 14 Feb 2005 03:03:58 GMT  
 Close form after opening report.
Sounds great but her is more information to my problem...

I have Form that lists all visible Reports. When the user
clicks on a report name it opens that report. That part
works.

I have this one Report ("Custom Report") that opens a Form
("Form1") during its OnOpen routine. "Form1" shows all
available fields for selecting to a custom report. There
is a button on Form1 to open this new Report ("Report1").
My problem is trying to close "Custom Report".

TIA,
    Jeff

Quote:
>-----Original Message-----
>If the report is always opened from the same form, it's
very easy -
>DoCmd.Close acForm, "NameOfFormHere"

>If the report can be opened by more than one form, it
get's a bit more
>complicated. One approach would be to have code in the
form put it's name
>into a global variable, and have the report get the form
name from there.

>In Access 2002, the OpenReport method has an OpenArgs
argument that you
>could use to pass the name of the form.

>--
>Brendan Reynolds (MVP)

>Access 2000/2002 sample app at
>http://brenreyn.brinkster.net
>----------------------------


>> Is there a way to have a report close the form that
opens
>> the report?

>> TIA,
>>      Jeff R

>.



Mon, 14 Feb 2005 03:30:57 GMT  
 Close form after opening report.
Further INFO

Using Access97

In Form1's OnOpen Event using For Each rpt in
Reports...Close...Next rpt this gives me an Error 2585:
This action can't be carried out while processing a form
or report event.

Jeff

Quote:
>-----Original Message-----
>If the report is always opened from the same form, it's
very easy -
>DoCmd.Close acForm, "NameOfFormHere"

>If the report can be opened by more than one form, it
get's a bit more
>complicated. One approach would be to have code in the
form put it's name
>into a global variable, and have the report get the form
name from there.

>In Access 2002, the OpenReport method has an OpenArgs
argument that you
>could use to pass the name of the form.

>--
>Brendan Reynolds (MVP)

>Access 2000/2002 sample app at
>http://brenreyn.brinkster.net
>----------------------------


>> Is there a way to have a report close the form that
opens
>> the report?

>> TIA,
>>      Jeff R

>.



Mon, 14 Feb 2005 03:34:25 GMT  
 Close form after opening report.
Sorry, Jeff, but I'm not sure I follow what the problem is? As I understand
it, when you open the report 'Report1', you want to close the form 'Custom
Report'? If so, why does the suggestion I previously posted not work for
you?

--
Brendan Reynolds (MVP)

Access 2000/2002 sample app at
http://brenreyn.brinkster.net
----------------------------

Quote:
> Sounds great but her is more information to my problem...

> I have Form that lists all visible Reports. When the user
> clicks on a report name it opens that report. That part
> works.

> I have this one Report ("Custom Report") that opens a Form
> ("Form1") during its OnOpen routine. "Form1" shows all
> available fields for selecting to a custom report. There
> is a button on Form1 to open this new Report ("Report1").
> My problem is trying to close "Custom Report".

> TIA,
>     Jeff

> >-----Original Message-----
> >If the report is always opened from the same form, it's
> very easy -
> >DoCmd.Close acForm, "NameOfFormHere"

> >If the report can be opened by more than one form, it
> get's a bit more
> >complicated. One approach would be to have code in the
> form put it's name
> >into a global variable, and have the report get the form
> name from there.

> >In Access 2002, the OpenReport method has an OpenArgs
> argument that you
> >could use to pass the name of the form.

> >--
> >Brendan Reynolds (MVP)

> >Access 2000/2002 sample app at
> >http://brenreyn.brinkster.net
> >----------------------------


> >> Is there a way to have a report close the form that
> opens
> >> the report?

> >> TIA,
> >>      Jeff R

> >.



Mon, 14 Feb 2005 17:46:24 GMT  
 Close form after opening report.
The Close method has some optional arguments you can use to tell it which
object to close (see the example I posted earlier). If you don't specify
those arguments, it attempts to close the active object - which in this case
would be the form instead of the report.

--
Brendan Reynolds (MVP)

Access 2000/2002 sample app at
http://brenreyn.brinkster.net
----------------------------

Quote:
> Further INFO

> Using Access97

> In Form1's OnOpen Event using For Each rpt in
> Reports...Close...Next rpt this gives me an Error 2585:
> This action can't be carried out while processing a form
> or report event.

> Jeff

> >-----Original Message-----
> >If the report is always opened from the same form, it's
> very easy -
> >DoCmd.Close acForm, "NameOfFormHere"

> >If the report can be opened by more than one form, it
> get's a bit more
> >complicated. One approach would be to have code in the
> form put it's name
> >into a global variable, and have the report get the form
> name from there.

> >In Access 2002, the OpenReport method has an OpenArgs
> argument that you
> >could use to pass the name of the form.

> >--
> >Brendan Reynolds (MVP)

> >Access 2000/2002 sample app at
> >http://brenreyn.brinkster.net
> >----------------------------


> >> Is there a way to have a report close the form that
> opens
> >> the report?

> >> TIA,
> >>      Jeff R

> >.



Mon, 14 Feb 2005 17:50:59 GMT  
 Close form after opening report.
The following module is in the "Custom Report" report and
is the only this in this report:
***************************************************
Private Sub Report_Open(Cancel As Integer)
    DoCmd.Minimize
    DoCmd.OpenForm "Form1", acNormal
End Sub
***************************************************

The following code is from "Form1" form:
***************************************************
Private Sub Form_Open(Cancel As Integer)
    For Each rpt In Reports
        DoCmd.Close acReport, rpt.Name
    Next rpt
    DoCmd.Restore
    UpdateList
    Me![lstFields].Requery
    Me![lstSelected].Requery
End Sub
***************************************************

The Close command above is what gives me the
error. "Custom Report" always runs first.

Jeff

Quote:
>-----Original Message-----
>Sorry, Jeff, but I'm not sure I follow what the problem
is? As I understand
>it, when you open the report 'Report1', you want to close
the form 'Custom
>Report'? If so, why does the suggestion I previously
posted not work for
>you?

>--
>Brendan Reynolds (MVP)

>Access 2000/2002 sample app at
>http://brenreyn.brinkster.net
>----------------------------


>> Sounds great but her is more information to my
problem...

>> I have Form that lists all visible Reports. When the
user
>> clicks on a report name it opens that report. That part
>> works.

>> I have this one Report ("Custom Report") that opens a
Form
>> ("Form1") during its OnOpen routine. "Form1" shows all
>> available fields for selecting to a custom report. There
>> is a button on Form1 to open this new Report
("Report1").
>> My problem is trying to close "Custom Report".

>> TIA,
>>     Jeff

>> >-----Original Message-----
>> >If the report is always opened from the same form, it's
>> very easy -
>> >DoCmd.Close acForm, "NameOfFormHere"

>> >If the report can be opened by more than one form, it
>> get's a bit more
>> >complicated. One approach would be to have code in the
>> form put it's name
>> >into a global variable, and have the report get the
form
>> name from there.

>> >In Access 2002, the OpenReport method has an OpenArgs
>> argument that you
>> >could use to pass the name of the form.

>> >--
>> >Brendan Reynolds (MVP)

>> >Access 2000/2002 sample app at
>> >http://brenreyn.brinkster.net
>> >----------------------------


>> >> Is there a way to have a report close the form that
>> opens
>> >> the report?

>> >> TIA,
>> >>      Jeff R

>> >.

>.



Mon, 14 Feb 2005 21:21:55 GMT  
 Close form after opening report.
Well, in the Open event of the report, you are opening a form, in the Open
event of which is code that tries to close all open reports - including the
report that you just opened. I don't understand why you're opening the
report just to close it again. But that's the reason for the error message -
at this point, the report's Open event is still running, and you can't close
it until that event has completed. If you want to cancel the opening of the
report, in it's Open event, set the Cancel argument to True.

--
Brendan Reynolds (MVP)

Access 2000/2002 sample app at
http://brenreyn.brinkster.net
----------------------------

Quote:
> The following module is in the "Custom Report" report and
> is the only this in this report:
> ***************************************************
> Private Sub Report_Open(Cancel As Integer)
>     DoCmd.Minimize
>     DoCmd.OpenForm "Form1", acNormal
> End Sub
> ***************************************************

> The following code is from "Form1" form:
> ***************************************************
> Private Sub Form_Open(Cancel As Integer)
>     For Each rpt In Reports
>         DoCmd.Close acReport, rpt.Name
>     Next rpt
>     DoCmd.Restore
>     UpdateList
>     Me![lstFields].Requery
>     Me![lstSelected].Requery
> End Sub
> ***************************************************

> The Close command above is what gives me the
> error. "Custom Report" always runs first.

> Jeff

> >-----Original Message-----
> >Sorry, Jeff, but I'm not sure I follow what the problem
> is? As I understand
> >it, when you open the report 'Report1', you want to close
> the form 'Custom
> >Report'? If so, why does the suggestion I previously
> posted not work for
> >you?

> >--
> >Brendan Reynolds (MVP)

> >Access 2000/2002 sample app at
> >http://brenreyn.brinkster.net
> >----------------------------


> >> Sounds great but her is more information to my
> problem...

> >> I have Form that lists all visible Reports. When the
> user
> >> clicks on a report name it opens that report. That part
> >> works.

> >> I have this one Report ("Custom Report") that opens a
> Form
> >> ("Form1") during its OnOpen routine. "Form1" shows all
> >> available fields for selecting to a custom report. There
> >> is a button on Form1 to open this new Report
> ("Report1").
> >> My problem is trying to close "Custom Report".

> >> TIA,
> >>     Jeff

> >> >-----Original Message-----
> >> >If the report is always opened from the same form, it's
> >> very easy -
> >> >DoCmd.Close acForm, "NameOfFormHere"

> >> >If the report can be opened by more than one form, it
> >> get's a bit more
> >> >complicated. One approach would be to have code in the
> >> form put it's name
> >> >into a global variable, and have the report get the
> form
> >> name from there.

> >> >In Access 2002, the OpenReport method has an OpenArgs
> >> argument that you
> >> >could use to pass the name of the form.

> >> >--
> >> >Brendan Reynolds (MVP)

> >> >Access 2000/2002 sample app at
> >> >http://brenreyn.brinkster.net
> >> >----------------------------


> >> >> Is there a way to have a report close the form that
> >> opens
> >> >> the report?

> >> >> TIA,
> >> >>      Jeff R

> >> >.

> >.



Tue, 15 Feb 2005 01:57:47 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Open form, close form, open form = disposed object exception

2. Time Delay, close current form, open new form

3. Code to close report if open

4. Forms, primary thread closing when closing startup form

5. Form Close Button Does Not Close the Form

6. Crystal 7 and VB app - Report opens and closes

7. Open Form On Close DB Event

8. Close all open forms? (urgent)

9. form open & close code mixup

10. Basic Question, about Close & Open Form

11. Open and Closing Forms

12. Closing All Open Forms

 

 
Powered by phpBB® Forum Software