Print current record in the form

G

GailK

Good afternoon,

-Access 2000
-taken form and put into report in order to print the record being viewed
-print command on form : found and used the following two codes but neither
one allows me to print just the one record.. getting all records. Have
searched all threads to determine cause but unable to locate why/a fix.
-primary key [Record] is a number type field

Thank you!

Code 1:
Private Sub cmdPrint_Click()
On Error GoTo Err_Handler

Dim stDocName As String
Dim stWhere As String

stDocName = "FormViewReport"
stWhere = "[Record] =" & Me![Record]
DoCmd.OpenReport stDocName, acViewNormal, , stWhere

Err_Exit:
Exit Sub

Err_Handler:
MsgBox Err.Description
Resume Err_Exit

Code 2:
Private Sub cmdPrint_Click()
Dim stWhere As String

If Me.Dirty Then
Me.Dirty=False
End If

If Me.NewRecord Then
MsgBox "Select a record to print"
Else
strWhere = "[Record] = " & Me.[Record]
DoCmd.OpenReport "FormViewReport", acViewNormal, , strWhere
End If
End Sub
 
O

Ofer Cohen

The code seems to be OK,
1. Check the report, is there anything on the Open event of the report that
might assign a different RecordSource to the report?

2. Is the data displayed on a SubReport and not the main report? if so the
filter will work only on the main report, the sub report doesnt recognize the
filter.
 
G

GailK

There is no coding within the report, specifically OnOpen event as well there
is no subreport being used.

I deleted the print button, report and OnClick event in case I had done some
obscure change. Resaved the form as a report, created a new command print
button with Code 2 below and still no success. In fact, I do not get the
MsgBox asking to select a record. Does it matter where in the form the print
button is placed - report header vs detail? I'm grasping at this point.

thx!

Ofer Cohen said:
The code seems to be OK,
1. Check the report, is there anything on the Open event of the report that
might assign a different RecordSource to the report?

2. Is the data displayed on a SubReport and not the main report? if so the
filter will work only on the main report, the sub report doesnt recognize the
filter.

--
Good Luck
BS"D


GailK said:
Good afternoon,

-Access 2000
-taken form and put into report in order to print the record being viewed
-print command on form : found and used the following two codes but neither
one allows me to print just the one record.. getting all records. Have
searched all threads to determine cause but unable to locate why/a fix.
-primary key [Record] is a number type field

Thank you!

Code 1:
Private Sub cmdPrint_Click()
On Error GoTo Err_Handler

Dim stDocName As String
Dim stWhere As String

stDocName = "FormViewReport"
stWhere = "[Record] =" & Me![Record]
DoCmd.OpenReport stDocName, acViewNormal, , stWhere

Err_Exit:
Exit Sub

Err_Handler:
MsgBox Err.Description
Resume Err_Exit

Code 2:
Private Sub cmdPrint_Click()
Dim stWhere As String

If Me.Dirty Then
Me.Dirty=False
End If

If Me.NewRecord Then
MsgBox "Select a record to print"
Else
strWhere = "[Record] = " & Me.[Record]
DoCmd.OpenReport "FormViewReport", acViewNormal, , strWhere
End If
End Sub
 
O

Ofer Cohen

Open the immidiate window (press Ctrl+G) , in it type

DoCmd.OpenReport stDocName, , , "[Record] =3"

write a real record type that exist and press enter, does it filter the
report?

--
Good Luck
BS"D


GailK said:
There is no coding within the report, specifically OnOpen event as well there
is no subreport being used.

I deleted the print button, report and OnClick event in case I had done some
obscure change. Resaved the form as a report, created a new command print
button with Code 2 below and still no success. In fact, I do not get the
MsgBox asking to select a record. Does it matter where in the form the print
button is placed - report header vs detail? I'm grasping at this point.

thx!

Ofer Cohen said:
The code seems to be OK,
1. Check the report, is there anything on the Open event of the report that
might assign a different RecordSource to the report?

2. Is the data displayed on a SubReport and not the main report? if so the
filter will work only on the main report, the sub report doesnt recognize the
filter.

--
Good Luck
BS"D


GailK said:
Good afternoon,

-Access 2000
-taken form and put into report in order to print the record being viewed
-print command on form : found and used the following two codes but neither
one allows me to print just the one record.. getting all records. Have
searched all threads to determine cause but unable to locate why/a fix.
-primary key [Record] is a number type field

Thank you!

Code 1:
Private Sub cmdPrint_Click()
On Error GoTo Err_Handler

Dim stDocName As String
Dim stWhere As String

stDocName = "FormViewReport"
stWhere = "[Record] =" & Me![Record]
DoCmd.OpenReport stDocName, acViewNormal, , stWhere

Err_Exit:
Exit Sub

Err_Handler:
MsgBox Err.Description
Resume Err_Exit

Code 2:
Private Sub cmdPrint_Click()
Dim stWhere As String

If Me.Dirty Then
Me.Dirty=False
End If

If Me.NewRecord Then
MsgBox "Select a record to print"
Else
strWhere = "[Record] = " & Me.[Record]
DoCmd.OpenReport "FormViewReport", acViewNormal, , strWhere
End If
End Sub
 
G

GailK

No... this was my code
DoCmd.OpenReport "FormViewReport", , , "[Record]=2"

Received Compile Error : Invalid outside procedure ... "FormViewReport"
highlighted.

thx


Ofer Cohen said:
Open the immidiate window (press Ctrl+G) , in it type

DoCmd.OpenReport stDocName, , , "[Record] =3"

write a real record type that exist and press enter, does it filter the
report?

--
Good Luck
BS"D


GailK said:
There is no coding within the report, specifically OnOpen event as well there
is no subreport being used.

I deleted the print button, report and OnClick event in case I had done some
obscure change. Resaved the form as a report, created a new command print
button with Code 2 below and still no success. In fact, I do not get the
MsgBox asking to select a record. Does it matter where in the form the print
button is placed - report header vs detail? I'm grasping at this point.

thx!

Ofer Cohen said:
The code seems to be OK,
1. Check the report, is there anything on the Open event of the report that
might assign a different RecordSource to the report?

2. Is the data displayed on a SubReport and not the main report? if so the
filter will work only on the main report, the sub report doesnt recognize the
filter.

--
Good Luck
BS"D


:

Good afternoon,

-Access 2000
-taken form and put into report in order to print the record being viewed
-print command on form : found and used the following two codes but neither
one allows me to print just the one record.. getting all records. Have
searched all threads to determine cause but unable to locate why/a fix.
-primary key [Record] is a number type field

Thank you!

Code 1:
Private Sub cmdPrint_Click()
On Error GoTo Err_Handler

Dim stDocName As String
Dim stWhere As String

stDocName = "FormViewReport"
stWhere = "[Record] =" & Me![Record]
DoCmd.OpenReport stDocName, acViewNormal, , stWhere

Err_Exit:
Exit Sub

Err_Handler:
MsgBox Err.Description
Resume Err_Exit

Code 2:
Private Sub cmdPrint_Click()
Dim stWhere As String

If Me.Dirty Then
Me.Dirty=False
End If

If Me.NewRecord Then
MsgBox "Select a record to print"
Else
strWhere = "[Record] = " & Me.[Record]
DoCmd.OpenReport "FormViewReport", acViewNormal, , strWhere
End If
End Sub
 
J

JimBadHair

This seems to be a bit of both your Code options.

It is working for me currently. If it still doesn't work, you might ask
someone if the field name"[Record]" is valid (or recommended) field name.
Access may be treating the field name as a command or something. Maybe try
and name that field [Record1].



Private Sub cmdPrint_Click()
On Error GoTo Err_Handler

Dim stDocName As String

DoCmd.OpenReport stDocName, acViewNormal, , "[Record] =" &
Me![Record][Record] = Forms![FormFromWhichYouarePrinting]![Record]"
Err_Exit:
Exit Sub

Err_Handler:
MsgBox Err.Description
Resume Err_Exit
 
J

JimBadHair

Oops forgot to delete your original code from my modified ver.

DoCmd.OpenReport stDocName, acViewNormal, , "[Record] =
Forms![FormFromWhichYouarePrinting]![Record]"

JimBadHair said:
This seems to be a bit of both your Code options.

It is working for me currently. If it still doesn't work, you might ask
someone if the field name"[Record]" is valid (or recommended) field name.
Access may be treating the field name as a command or something. Maybe try
and name that field [Record1].



Private Sub cmdPrint_Click()
On Error GoTo Err_Handler

Dim stDocName As String

DoCmd.OpenReport stDocName, acViewNormal, , "[Record] = Forms![FormFromWhichYouarePrinting]![Record]"
Err_Exit:
Exit Sub

Err_Handler:
MsgBox Err.Description
Resume Err_Exit

GailK said:
Good afternoon,

-Access 2000
-taken form and put into report in order to print the record being viewed
-print command on form : found and used the following two codes but neither
one allows me to print just the one record.. getting all records. Have
searched all threads to determine cause but unable to locate why/a fix.
-primary key [Record] is a number type field

Thank you!

Code 1:
Private Sub cmdPrint_Click()
On Error GoTo Err_Handler

Dim stDocName As String
Dim stWhere As String

stDocName = "FormViewReport"
stWhere = "[Record] =" & Me![Record]
DoCmd.OpenReport stDocName, acViewNormal, , stWhere

Err_Exit:
Exit Sub

Err_Handler:
MsgBox Err.Description
Resume Err_Exit

Code 2:
Private Sub cmdPrint_Click()
Dim stWhere As String

If Me.Dirty Then
Me.Dirty=False
End If

If Me.NewRecord Then
MsgBox "Select a record to print"
Else
strWhere = "[Record] = " & Me.[Record]
DoCmd.OpenReport "FormViewReport", acViewNormal, , strWhere
End If
End Sub
 
G

GailK

It's working now.... I changed Record to RecordNumber and used your coding
below so now the command prints the current record. I appreciate your
assistance!!

Thanks
Gail

JimBadHair said:
Oops forgot to delete your original code from my modified ver.

DoCmd.OpenReport stDocName, acViewNormal, , "[Record] =
Forms![FormFromWhichYouarePrinting]![Record]"

JimBadHair said:
This seems to be a bit of both your Code options.

It is working for me currently. If it still doesn't work, you might ask
someone if the field name"[Record]" is valid (or recommended) field name.
Access may be treating the field name as a command or something. Maybe try
and name that field [Record1].



Private Sub cmdPrint_Click()
On Error GoTo Err_Handler

Dim stDocName As String

DoCmd.OpenReport stDocName, acViewNormal, , "[Record] = Forms![FormFromWhichYouarePrinting]![Record]"
Err_Exit:
Exit Sub

Err_Handler:
MsgBox Err.Description
Resume Err_Exit

GailK said:
Good afternoon,

-Access 2000
-taken form and put into report in order to print the record being viewed
-print command on form : found and used the following two codes but neither
one allows me to print just the one record.. getting all records. Have
searched all threads to determine cause but unable to locate why/a fix.
-primary key [Record] is a number type field

Thank you!

Code 1:
Private Sub cmdPrint_Click()
On Error GoTo Err_Handler

Dim stDocName As String
Dim stWhere As String

stDocName = "FormViewReport"
stWhere = "[Record] =" & Me![Record]
DoCmd.OpenReport stDocName, acViewNormal, , stWhere

Err_Exit:
Exit Sub

Err_Handler:
MsgBox Err.Description
Resume Err_Exit

Code 2:
Private Sub cmdPrint_Click()
Dim stWhere As String

If Me.Dirty Then
Me.Dirty=False
End If

If Me.NewRecord Then
MsgBox "Select a record to print"
Else
strWhere = "[Record] = " & Me.[Record]
DoCmd.OpenReport "FormViewReport", acViewNormal, , strWhere
End If
End Sub
 

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

Top