Form On exit event

G

Guest

I have posted this thread last week.
I apologize for posting it again but I could not solve my question.

May be someone else can give me an idea.

I need when closing a form to open a report on a specific record.
So, I have this code:

Private Sub Form_close()
DoCmd.OpenReport "Invoice", acViewPreview, , "[DocId] = """ & Me.[DocID]
& """", acNormal

End Sub

The problem is that it opens the report always on the first record, no
matter which DocId I have.

If I run the code without closing the form it works fine.
I guess that the Form_close() event runs the code after closing the form and
so Me.DocId is Null.

Is there any way for running the code before closing the form?
 
R

Rick Brandt

Raul said:
I have posted this thread last week.
I apologize for posting it again but I could not solve my question.

May be someone else can give me an idea.

I need when closing a form to open a report on a specific record.
So, I have this code:

Private Sub Form_close()
DoCmd.OpenReport "Invoice", acViewPreview, , "[DocId] = """ &
Me.[DocID] & """", acNormal

End Sub

The problem is that it opens the report always on the first record, no
matter which DocId I have.

If I run the code without closing the form it works fine.
I guess that the Form_close() event runs the code after closing the
form and so Me.DocId is Null.

Is there any way for running the code before closing the form?

Try the Unload event instead. The control might no longer contain a value
in the Close event.
 
N

Nick 'The database Guy'

Hi Raul,

Try putting in a message box in the sub, msgbox [DocId] for instance
that way you try and insolate the bug.

Also why have you got three sets of speach marks next to each other?

Try assigning the argument "[DocId] = """ & Me.[DocID] > & """" to a
variable and setting a breakpoint and check what is value is.

Good luck,

Nick
 
G

Guest

Thank you both for your reply.
I have used the message box for debug and I found that:
• When the code is run on exit event control´s value is trhe first record.
• When the code is run elsewhere but on exit event control´s value OK.
So, I have used the unload event … and it worked

"Rick Brandt" escreveu:
Raul said:
I have posted this thread last week.
I apologize for posting it again but I could not solve my question.

May be someone else can give me an idea.

I need when closing a form to open a report on a specific record.
So, I have this code:

Private Sub Form_close()
DoCmd.OpenReport "Invoice", acViewPreview, , "[DocId] = """ &
Me.[DocID] & """", acNormal

End Sub

The problem is that it opens the report always on the first record, no
matter which DocId I have.

If I run the code without closing the form it works fine.
I guess that the Form_close() event runs the code after closing the
form and so Me.DocId is Null.

Is there any way for running the code before closing the form?

Try the Unload event instead. The control might no longer contain a value
in the Close event.
 

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