• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 244
  • Last Modified:

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.)
0
Faircarp
Asked:
Faircarp
  • 2
1 Solution
 
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

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now