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
Rick B - 31 Jul 2006 20:17 GMT
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

Signature
Rick B
> 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].
[quoted text clipped - 19 lines]
>
> Thx, Dj
Dj - 31 Jul 2006 21:15 GMT
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!
> 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].
[quoted text clipped - 14 lines]
>
> Thx, Dj
Rick B - 31 Jul 2006 21:22 GMT
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.

Signature
Rick B
> Never having worked with the Dirty Event, I was reading up on it in help
> menu
[quoted text clipped - 28 lines]
>>
>> Thx, Dj
fredg - 31 Jul 2006 21:28 GMT
> 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].
[quoted text clipped - 14 lines]
>
> 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.

Signature
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail