Commit recordset update from form without losing position

I have a form that is used to add or edit  records in a table. After entering changes in 1 or more fields I want to print a report based upon the active record that will reflect the changes, but I want the form to remain open on the same record. (This is an Access database, not SQL.)
FaircarpAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pique_techCommented:
This shouldn't be very difficult at all.

Create a report that includes the information about the record you want to print and put a command button on the form to open that report.  Then have code like this to open the report on the Click event of your new button:
DoCmd.OpenReport "ReportName", acViewPreview, , "[NameOfIDFieldInReport]=" & NameOfIDFieldOnForm ,acWindowNormal

This will open the report, filtering for the record currently open in the form, and will not change the record open on the form.  When you're done with the report, you can close it, and your form should be as you left it.
0
pique_techCommented:
If you need more detailed information, just post here.
0
stevbeCommented:
1. You need to make sure the record is saved.
2. You can pass the Primary Key field as criteria to your report.

Private Sub cmdPreview_Click()

    'make sure current record has been saved
    If Me.Dirty = True Then
        Me.Dirty = False
    End If

    'open report with criteria of current record
    DoCmd.OpenReport ReportName:="MyReport", _
                                 View:=acPreview
                                 WhereCondition:="MyField=" & Me.txtMyField
End Sub

Replace MyReport with the name of your report
Replace MyField with the name of the PrimaryKey field for the record you want to print
Replace txtMyField with the name of the control that is bound to your Primary Key field.

If your Primary Key field is stored as Text in the table then surround the value with '

                                 WhereCondition:="MyField='" & Me.txtMyField & "'"

Steve
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.