report's onCLOSE executes ONOPEN (AND onclose)!?!?!?

B

Bob

running access 2k;

I have a form that opens a report, and an onclose event in the report
that updates a table when the report closes.

here's the code for my button's onclick event in the form:
DoCmd.OpenReport strRptname, acViewPreview
Reports(strRptname).FilterOn = False
Reports(strRptname).Filter = "pin = '" & pin.Value & "'"
Reports(strRptname).FilterOn = True


currently, for testing, my onclose event for the report simply is:
msgbox("updating my tables now")


What I want SEEMS very simple! - I want a user to push a button to open
a report, and when the report closes, I want to update a record in a
table.

What happens is this: the ---- onclose event triggers when the report
is opened!!!
If I open this report WITHOUT using a form - it works perfectly.
When I use a form to open it - onclose triggers TWICE - when the report
OPENS, AND when it closes!?!?!?

After monkeying around for untold hours, I cannot get what I want. I've
tried dozens of differing programmatic solutions - NONE work.

I either get the event triggered when the report opens (and closes), or
I get my msgbox Before I can even see the report.

anyone have a clue?
TIA - Bob
 
D

Duane Hookom

Try change your code to
Dim strWhere as String
strWhere = "pin = '" & Me.pin & "'"
DoCmd.OpenReport strRptname, acViewPreview, , strWhere
 
B

Bob

O-K....

That was 1 thing I didn't try, and sure enough it does work.
I'm Extremely confused as to why changing around with the report.filter
should mess up an event's execution.

Further - I tried the following:
strWhere = "pin = '" & Me.pin & "'"
DoCmd.OpenReport strRptname, acViewPreview, , strWhere
Reports(strRptname).FilterOn = False
Reports(strRptname).OnClose = "=reportOK"

(in the report I have sub reportOK() which is:)
msgbox ("updating the table")


This at least works better than any of my previous attempts, BUT -
the onclose executes THREE times!

The reason I'm doing this, is because this report normally prints many
records. However, when a user pushes the button on this form, I want
the report to print only 1 record.

SO - I must disable the filter that I've saved with the report (which
BTW, only prints previously un-printed records); and then try to insert
an onclose event that should ONLY execute if this is a "1-off" report.

Clearly, I can make all this work, by simply copying the report, and
using the copy (altered for this purpose) - but then I have 2 identical
reports to maintain.


I can certainly see the simplicity in your solution, but I'm still not
clear what was wrong with mine. Logically it should perform
identically.

TX again IA...
Bob
 
D

Duane Hookom

I try to avoid code in one object that modifies properties of another object
so I haven't seen your issue. I expect that changing the Filter may close
the report and then re-open it. I believe this happens when going from
preview to print.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top