vbYesNo when closing report

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I would like to be able to prompt the user when closing my report with a
vbYesNo and I can't seem to get the code quite right. First off, should I
have the code in the On Close event of the report? I would like it if the
user selects yes to close the report and the form that the user was entering
data which would take them back to my switchboard. If they select no, I would
like it to just close the report and take them back to the form they were
entering data. Please Help!

Thanks!
 
Hi.
First off, should I
have the code in the On Close event of the report?

The OnClose( ) event is an excellent candidate. And if the report has been
opened in dialog mode, then the calling function could execute this code
right after opening the report, too.
I would like it if the
user selects yes to close the report and the form that the user was entering
data which would take them back to my switchboard. If they select no, I would
like it to just close the report and take them back to the form they were
entering data.

In the following example using the report's OnClose( ) event, frmDataEntry
is the name of the data entry form and frmSwitchboard is the name of the
switchboard form.

' * * * * Start Code * * * *

Private Sub Report_Close()

On Error GoTo ErrHandler

Dim ans As Integer

ans = MsgBox("Are you finished entering data?", vbYesNo + vbInformation, _
"Close Report")

If (ans = vbYes) Then
DoCmd.Close acForm, "frmDataEntry"
DoCmd.OpenForm "frmSwitchboard"
Else
DoCmd.OpenForm "frmDataEntry"
End If

Exit Sub

ErrHandler:

MsgBox "Error in Report_Close( )." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear

End Sub

' * * * * End Code * * * *

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
Back
Top