By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,248 Members | 1,979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,248 IT Pros & Developers. It's quick & easy.

Go To Rcord Number x - how do I write macro

P: n/a
I want to go from viewing a form (record number "x") to the same record
("x") in a report.

Of course, when I open the report, it opens to the first record, not record
"x".

I don't know VBA, only macros.

Is there any way to do this with macros (I tried time stamping a field in
the form when I enter a record and then using a query to sort by max date as
the basis for the report but this doesn't seem to work).

Thanks

(Access 2000)
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Well you can do :
File>Print>Printselectedrecord

Or you can create a report which prints your data, then a macro which
opens the report, and finally a button on your form which runs the macro.

If you create a macro you use the OpenReport action and then you need to
set the 'Where' parameter.

You'll need something like:

[ID]=[Forms]![frmMyForm]![ID]

using your own field and form names.

Regards

Peter Russell
Edgar previously wrote:
I want to go from viewing a form (record number "x") to the same record
("x") in a report.

Of course, when I open the report, it opens to the first record, not
record
"x".

I don't know VBA, only macros.

Is there any way to do this with macros (I tried time stamping a field
in
the form when I enter a record and then using a query to sort by max
date as
the basis for the report but this doesn't seem to work).

Thanks

(Access 2000)


Nov 12 '05 #2

P: n/a
"Edgar" <x @ none.com.invalid> wrote in message news:<rH********************@news04.bloor.is.net.c able.rogers.com>...
I want to go from viewing a form (record number "x") to the same record
("x") in a report.


Can't perform this event with a macro.
Create a command button on your form in the Design view. Right-click
it with your mouse.Under the properties window, Name it
Command1.Scroll down the menu to the On Click event.Fill in the line
with Event Procedure. Move to the end of the line and a little box
with ... will appear.This opens a code window.In the On Click event
Procedure, paste this VBA code:

Private Sub Command1_Click()
On Error GoTo Err_Command1_Click

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Report" 'Name of report goes here

stLinkCriteria = "[Document_ID]=" & Me![Document_ID] 'links the
report item to the form item using Document_ID as the primary key
name. Textboxes with this name must appear on both the form and the
report-make them not visible with the Properties box.

DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
Exit_Command1_Click:
Exit Sub

Err_Command1_Click:
MsgBox Err.Description
Resume Exit_Command1_Click

End Sub
Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.