Print/Preview Current record

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

Guest

Hi
I have set the cycle function on my Orders form to "Current". When I enter a
new order on the Orders form, I would like to be able to preview or print it.
I have tried using a macro to first save the orders form prior to previewing
or printing it, but I end up with a blank report. I can pull up a prior order
and preview/print it with no problem or I can go to cycle function "All
Records" on the form, tab to next record, and back up to the current record.
I want to use the cycle function "Current" if possible.
Thanks for any help on this.
 
Hi
I have set the cycle function on my Orders form to "Current". When I enter a
new order on the Orders form, I would like to be able to preview or print it.
I have tried using a macro to first save the orders form prior to previewing
or printing it, but I end up with a blank report. I can pull up a prior order
and preview/print it with no problem or I can go to cycle function "All
Records" on the form, tab to next record, and back up to the current record.
I want to use the cycle function "Current" if possible.
Thanks for any help on this.




A new record is saved when you close the form, go to another record,
or explicitly save the record (not by saving the form).
The Form's cycle property is irrelevant, except that by setting it to
current the record, the current record isn't saved (because you
haven't gone to the next record).

Your table should have a unique prime key field.
In my example it is named [RecordID].

On the command button's property sheet write
[Event Procedure]
on the Click event line.
Then click on the little button with 3 dots that will appear on that
line.
When the code window opens, the cursor will be flashing between 2
already existing lines of code.
Between those 2 lines write:

' Save the record
DoCmd.RunCommand acCmdSaveRecord
' Open the report to just the record shown on the form
DoCmd.OpenReport "ReportName", acViewPreview, , "[RecordID] = " &
[RecordID]

Save the code.

The above assumes a [RecordID] field that is a Number Datatype.

If, however, [RecordID] is Text Datatype, then use:

DoCmd.OpenReport "ReportName", acViewPreview, ,"[RecordID] = '" &
[RecordID] & "'"

For clarity, the single and double quotes are..
"[RecordID] = ' " & [RecordID] & " ' "

Change [RecordID] to whatever the actual field name is that you are
using.

See VBA Help files for:
Where Clause + Restrict data to a subset of records'
 
Thanks Fred, you made that so easy. Now, if I'm not imposing too much,
suppose I just want to go straight to the print button? How might that code
look?

fredg said:
Hi
I have set the cycle function on my Orders form to "Current". When I enter a
new order on the Orders form, I would like to be able to preview or print it.
I have tried using a macro to first save the orders form prior to previewing
or printing it, but I end up with a blank report. I can pull up a prior order
and preview/print it with no problem or I can go to cycle function "All
Records" on the form, tab to next record, and back up to the current record.
I want to use the cycle function "Current" if possible.
Thanks for any help on this.




A new record is saved when you close the form, go to another record,
or explicitly save the record (not by saving the form).
The Form's cycle property is irrelevant, except that by setting it to
current the record, the current record isn't saved (because you
haven't gone to the next record).

Your table should have a unique prime key field.
In my example it is named [RecordID].

On the command button's property sheet write
[Event Procedure]
on the Click event line.
Then click on the little button with 3 dots that will appear on that
line.
When the code window opens, the cursor will be flashing between 2
already existing lines of code.
Between those 2 lines write:

' Save the record
DoCmd.RunCommand acCmdSaveRecord
' Open the report to just the record shown on the form
DoCmd.OpenReport "ReportName", acViewPreview, , "[RecordID] = " &
[RecordID]

Save the code.

The above assumes a [RecordID] field that is a Number Datatype.

If, however, [RecordID] is Text Datatype, then use:

DoCmd.OpenReport "ReportName", acViewPreview, ,"[RecordID] = '" &
[RecordID] & "'"

For clarity, the single and double quotes are..
"[RecordID] = ' " & [RecordID] & " ' "

Change [RecordID] to whatever the actual field name is that you are
using.

See VBA Help files for:
Where Clause + Restrict data to a subset of records'
 
Thanks Fred, you made that so easy. Now, if I'm not imposing too much,
suppose I just want to go straight to the print button? How might that code
look?

fredg said:
Hi
I have set the cycle function on my Orders form to "Current". When I enter a
new order on the Orders form, I would like to be able to preview or print it.
I have tried using a macro to first save the orders form prior to previewing
or printing it, but I end up with a blank report. I can pull up a prior order
and preview/print it with no problem or I can go to cycle function "All
Records" on the form, tab to next record, and back up to the current record.
I want to use the cycle function "Current" if possible.
Thanks for any help on this.

A new record is saved when you close the form, go to another record,
or explicitly save the record (not by saving the form).
The Form's cycle property is irrelevant, except that by setting it to
current the record, the current record isn't saved (because you
haven't gone to the next record).

Your table should have a unique prime key field.
In my example it is named [RecordID].

On the command button's property sheet write
[Event Procedure]
on the Click event line.
Then click on the little button with 3 dots that will appear on that
line.
When the code window opens, the cursor will be flashing between 2
already existing lines of code.
Between those 2 lines write:

' Save the record
DoCmd.RunCommand acCmdSaveRecord
' Open the report to just the record shown on the form
DoCmd.OpenReport "ReportName", acViewPreview, , "[RecordID] = " &
[RecordID]

Save the code.

The above assumes a [RecordID] field that is a Number Datatype.

If, however, [RecordID] is Text Datatype, then use:

DoCmd.OpenReport "ReportName", acViewPreview, ,"[RecordID] = '" &
[RecordID] & "'"

For clarity, the single and double quotes are..
"[RecordID] = ' " & [RecordID] & " ' "

Change [RecordID] to whatever the actual field name is that you are
using.

See VBA Help files for:
Where Clause + Restrict data to a subset of records'

Omit acViewPreview but retain the comma, or change acViewPreview to
acViewNormal
See VBA help on the OpenReport method.
 
Thanks again Fredg. I appreciate your help!

fredg said:
Thanks Fred, you made that so easy. Now, if I'm not imposing too much,
suppose I just want to go straight to the print button? How might that code
look?

fredg said:
On Wed, 25 Oct 2006 11:42:01 -0700, Ron Weaver wrote:

Hi
I have set the cycle function on my Orders form to "Current". When I enter a
new order on the Orders form, I would like to be able to preview or print it.
I have tried using a macro to first save the orders form prior to previewing
or printing it, but I end up with a blank report. I can pull up a prior order
and preview/print it with no problem or I can go to cycle function "All
Records" on the form, tab to next record, and back up to the current record.
I want to use the cycle function "Current" if possible.
Thanks for any help on this.

A new record is saved when you close the form, go to another record,
or explicitly save the record (not by saving the form).
The Form's cycle property is irrelevant, except that by setting it to
current the record, the current record isn't saved (because you
haven't gone to the next record).

Your table should have a unique prime key field.
In my example it is named [RecordID].

On the command button's property sheet write
[Event Procedure]
on the Click event line.
Then click on the little button with 3 dots that will appear on that
line.
When the code window opens, the cursor will be flashing between 2
already existing lines of code.
Between those 2 lines write:

' Save the record
DoCmd.RunCommand acCmdSaveRecord
' Open the report to just the record shown on the form
DoCmd.OpenReport "ReportName", acViewPreview, , "[RecordID] = " &
[RecordID]

Save the code.

The above assumes a [RecordID] field that is a Number Datatype.

If, however, [RecordID] is Text Datatype, then use:

DoCmd.OpenReport "ReportName", acViewPreview, ,"[RecordID] = '" &
[RecordID] & "'"

For clarity, the single and double quotes are..
"[RecordID] = ' " & [RecordID] & " ' "

Change [RecordID] to whatever the actual field name is that you are
using.

See VBA Help files for:
Where Clause + Restrict data to a subset of records'

Omit acViewPreview but retain the comma, or change acViewPreview to
acViewNormal
See VBA help on the OpenReport method.
 
Fred I have also followed your steps below but I am having some issues. When
I print I receive two printouts one in the report form that I want and the
other is a printout of the form itself. Can you tell me what I have to do to
stop the form image from printing?

fredg said:
Thanks Fred, you made that so easy. Now, if I'm not imposing too much,
suppose I just want to go straight to the print button? How might that code
look?

fredg said:
On Wed, 25 Oct 2006 11:42:01 -0700, Ron Weaver wrote:

Hi
I have set the cycle function on my Orders form to "Current". When I enter a
new order on the Orders form, I would like to be able to preview or print it.
I have tried using a macro to first save the orders form prior to previewing
or printing it, but I end up with a blank report. I can pull up a prior order
and preview/print it with no problem or I can go to cycle function "All
Records" on the form, tab to next record, and back up to the current record.
I want to use the cycle function "Current" if possible.
Thanks for any help on this.

A new record is saved when you close the form, go to another record,
or explicitly save the record (not by saving the form).
The Form's cycle property is irrelevant, except that by setting it to
current the record, the current record isn't saved (because you
haven't gone to the next record).

Your table should have a unique prime key field.
In my example it is named [RecordID].

On the command button's property sheet write
[Event Procedure]
on the Click event line.
Then click on the little button with 3 dots that will appear on that
line.
When the code window opens, the cursor will be flashing between 2
already existing lines of code.
Between those 2 lines write:

' Save the record
DoCmd.RunCommand acCmdSaveRecord
' Open the report to just the record shown on the form
DoCmd.OpenReport "ReportName", acViewPreview, , "[RecordID] = " &
[RecordID]

Save the code.

The above assumes a [RecordID] field that is a Number Datatype.

If, however, [RecordID] is Text Datatype, then use:

DoCmd.OpenReport "ReportName", acViewPreview, ,"[RecordID] = '" &
[RecordID] & "'"

For clarity, the single and double quotes are..
"[RecordID] = ' " & [RecordID] & " ' "

Change [RecordID] to whatever the actual field name is that you are
using.

See VBA Help files for:
Where Clause + Restrict data to a subset of records'

Omit acViewPreview but retain the comma, or change acViewPreview to
acViewNormal
See VBA help on the OpenReport method.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top