Run report on a forms I'm currently editing

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

Guest

My Form has a button which unts a Macro which prints a Report which is run
off of a Query whose criteria is [Forms]![My Form]![ID].

After having no luck with it displaying the current record I was editing,
through testing and debugging, I was able to determine that once the current
record I'm in is in edit mode (you know, with the little pencel icon), my
report won't print the changes I put in until I've left that record and go
back to it without entering edit mode.

My true desire is to run the report of a brand new record I just added, but
again, nothing will show in the report until I've left out of edit mode and
point back to the record without going into edit mode.

Can anyone tell me what I can do, possibly to my Macro, to get my record out
of edit mode right before I run the report so that I get my latest chagnges
in the report?

Thx, Dj
 
Not sure how to do this with a macro. But, using a button and code, you'd
do something similar to the following...

Button to print specific record
Private Sub cmdPrint_Click()

Dim strWhere As String

If Me.Dirty Then 'Save any edits.

Me.Dirty = False

End If

If Me.NewRecord Then 'Check there is a record to print

MsgBox "Select a record to print"

Else

strWhere = "[ID] = " & Me.[ID]

DoCmd.OpenReport "MyReport", acViewPreview, , strWhere

End If

End Sub



Notes: If your primary key is a Text type field (not a Number type field),
you need extra quotes: strWhere = "[ID] = """ & Me.[ID] & """"

If you want the report to print without preview, replace acViewPreview with
acViewNormal.



See also: http://allenbrowne.com/casu-15.html
 
Never having worked with the Dirty Event, I was reading up on it in help menu
near the bottom it references "Click Save Record on the Records Menu". I
actually think that would help too. However, I don't know where to find the
Records Menu. It is so simple I'm overlooking it? Thanks!
 
Dj, the code I posted will save a dirty record. No need to know where a
particular menu item is. Just copy the code and modify the names to match
your report name, field names, etc.

--
Rick B



Dj said:
Never having worked with the Dirty Event, I was reading up on it in help
menu
near the bottom it references "Click Save Record on the Records Menu". I
actually think that would help too. However, I don't know where to find
the
Records Menu. It is so simple I'm overlooking it? Thanks!

Dj said:
My Form has a button which unts a Macro which prints a Report which is
run
off of a Query whose criteria is [Forms]![My Form]![ID].

After having no luck with it displaying the current record I was editing,
through testing and debugging, I was able to determine that once the
current
record I'm in is in edit mode (you know, with the little pencel icon), my
report won't print the changes I put in until I've left that record and
go
back to it without entering edit mode.

My true desire is to run the report of a brand new record I just added,
but
again, nothing will show in the report until I've left out of edit mode
and
point back to the record without going into edit mode.

Can anyone tell me what I can do, possibly to my Macro, to get my record
out
of edit mode right before I run the report so that I get my latest
chagnges
in the report?

Thx, Dj
 
My Form has a button which unts a Macro which prints a Report which is run
off of a Query whose criteria is [Forms]![My Form]![ID].

After having no luck with it displaying the current record I was editing,
through testing and debugging, I was able to determine that once the current
record I'm in is in edit mode (you know, with the little pencel icon), my
report won't print the changes I put in until I've left that record and go
back to it without entering edit mode.

My true desire is to run the report of a brand new record I just added, but
again, nothing will show in the report until I've left out of edit mode and
point back to the record without going into edit mode.

Can anyone tell me what I can do, possibly to my Macro, to get my record out
of edit mode right before I run the report so that I get my latest chagnges
in the report?

Thx, Dj

Do is using code. It's very simple.
On the Command Button's click event line, write
[Event Procedure]

Then click on the little button with 3 dots that appears on that line.

The code window will open, with the cursor flashing between 2 already
written lines of code.
Between those 2 lines of code write:

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "ReportName", acViewPreview, , "[ID] = " & Me![ID]

The above assumes the [ID] field is a Number datatype.

If [ID] is Text datatype, use:
DoCmd.OpenReport "ReportName", acViewPreview, , "[ID] = '" & Me![ID] &
"'"

Save the changes.
 
Back
Top