Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem Closing and Reopening a Form

Status
Not open for further replies.

HenriM

Programmer
Sep 9, 2002
56
GB
I have a Form with two alternative Command Buttons, depending on data in a table which Changes as certain functions are completed.

One says "Print Draft Data" and, when this is actioned the completion date is entered on the table.

Next time the form is opened,the date under "Draft Data" is recognised, "Print Draft Data" is invisible and replaced by "Print Full Report" which is now visible.

I want, as soon as the Draft Data has been printed, the Form to close and reopen, showing the "Print Full Report" button.

Clearly it needs to show the original Record.

The Form opens originally with code from a preceding Form,

DoCmd.Openform "CReport",,ReportID = I

If, Before "End Sub" the Code states

DoCmd.Close acForm "CReport"
DoCmd.OpenForm "CReport"

the form colses and opens again, defaulting, obviously to the first Record - which we don't want.

BUT if I repeat the original command,
DoCmd.Openform "CReport",,ReportID = I

I get an error message which states:-

"The expression you entered refers to and object which is closed or not available"

In the Debug window, putting the mouse over &quot;ReportID&quot; I get the same message, preceded by &quot;Report ID =<&quot;. I, (the record number) is correct because it was declared and has not changed.

So for some reason,closing a form denies access to an object in that Form when I try to use it as a parameter for reopening.

There seems to be no Command like &quot;DoCmd.Refresh&quot; or &quot;DoCmd.Reset&quot; which would put us back to square one so that we could repoen afresh.

Has anyone any ideas?
 
There are two things I see.

1. What is ReportID? Is it a textbox/control of some sort? If so, you probably &quot;closed&quot; it when you closed the first form. To work around this, save the value in a temp variable in your procedure before closing the form, then use the temp variable to re-open the form.

2. I don't know what
Code:
DoCmd.Openform &quot;CReport&quot;,,ReportID = I
does. What is &quot;I&quot;? This line looks like it wouldn't work. Please explain the specifics of this line of code--this is where the problem is.

--
Find common answers using Google Groups:

Corrupt MDBs FAQ
 
Thanks foolio12 for your very quick response.

Let me try to clarify, as you request.

&quot;CReport&quot; is the name of the form.

&quot;ReportID&quot; is the ID of the record to be opened. As I said, the line of code does open the form without a problem first time around.

I use this line (substituting the form name as applicable) to open all the forms in the project, and it works every time.

&quot;I&quot; is the temporary value of &quot;ReportID&quot;, and is carried over correctly when the form is closed and a reopen attempt is made. It appears correctly in the Debug window.

What the system does not seem to like is the use of the name &quot;ReportID&quot; on the second attempt, and I can't think why. As I see it, the closure of the form takes us to the position we were in before the form was opened in the first place and it should open again, using the same line of code, without a problem.

As I write I have thought of another, much simpler way of achieving my objective without closing the form at all; I find this one of the great benefits of having to write down a problem for submission to tek-tips!!

But the technical question still intrigues me; why can't you close a form and then reopen it using the line of code which worked the first time?

If you have the answer to this I think it will be of general interest; but for the present, by making me restate my problem you have made me find the solution.

I won't bore you with it because it is so elementary that I should have used it in the first place, but

THANKS!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top