Forms - reports - current record

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

Guest

The user needs to be able to print reports from a form and only the report
that correlates to the current record. I am not sure how to do this, any
suggestions would be appreciated. Thanks
 
Jody,

Use the optional Where clause of the OpenReport method. If you've never
written an event procedure, place a command button in form design view and
show its properties with View, Properties. Click on the Event tab, and click
into the On Click field. An ellipsis will appear on the right-hand side;
click it, and select Code Builder (if necessary--it may not show, depending
on your configuration). Then cut and paste the code below between the
Sub..End Sub lines. Save and exit.

On Error GoTo Err_Handler

Dim stDocName As String
Dim stWhere As String

stDocName = "YourReport"
stWhere = "[YourField] =" & Me![YourCorrespondingFormControl]
DoCmd.OpenReport stDocName, acPreview, , stWhere

Err_Exit:
Exit Sub

Err_Handler:
MsgBox Err.Description
Resume Err_Exit

Sprinks
 
I am having a bit of trouble with this, I keep getting this error :

Data type mismatch in critera expression

This is the statement I am using and I would appreciate any help anyone can
give me.
On Error GoTo Err_Handler

Dim stDocName As String
Dim stWhere As String

stDocName = "GAP Worksheet"
stWhere = "[LoanLeaseNumber] =" & Me!LoanLeaseNumber
DoCmd.OpenReport stDocName, acPreview, , stWhere

Err_Exit:
Exit Sub

Err_Handler:
MsgBox Err.Description
Resume Err_Exit


Sprinks said:
Jody,

Use the optional Where clause of the OpenReport method. If you've never
written an event procedure, place a command button in form design view and
show its properties with View, Properties. Click on the Event tab, and click
into the On Click field. An ellipsis will appear on the right-hand side;
click it, and select Code Builder (if necessary--it may not show, depending
on your configuration). Then cut and paste the code below between the
Sub..End Sub lines. Save and exit.

On Error GoTo Err_Handler

Dim stDocName As String
Dim stWhere As String

stDocName = "YourReport"
stWhere = "[YourField] =" & Me![YourCorrespondingFormControl]
DoCmd.OpenReport stDocName, acPreview, , stWhere

Err_Exit:
Exit Sub

Err_Handler:
MsgBox Err.Description
Resume Err_Exit

Sprinks

Jody said:
The user needs to be able to print reports from a form and only the report
that correlates to the current record. I am not sure how to do this, any
suggestions would be appreciated. Thanks
 
Jody,

Sorry you're having trouble. Try:

stWhere = "[LoanLeaseNumber] =" & "'" & Me!LoanLeaseNumber & "'"

Sprinks

Jody said:
I am having a bit of trouble with this, I keep getting this error :

Data type mismatch in critera expression

This is the statement I am using and I would appreciate any help anyone can
give me.
On Error GoTo Err_Handler

Dim stDocName As String
Dim stWhere As String

stDocName = "GAP Worksheet"
stWhere = "[LoanLeaseNumber] =" & Me!LoanLeaseNumber
DoCmd.OpenReport stDocName, acPreview, , stWhere

Err_Exit:
Exit Sub

Err_Handler:
MsgBox Err.Description
Resume Err_Exit


Sprinks said:
Jody,

Use the optional Where clause of the OpenReport method. If you've never
written an event procedure, place a command button in form design view and
show its properties with View, Properties. Click on the Event tab, and click
into the On Click field. An ellipsis will appear on the right-hand side;
click it, and select Code Builder (if necessary--it may not show, depending
on your configuration). Then cut and paste the code below between the
Sub..End Sub lines. Save and exit.

On Error GoTo Err_Handler

Dim stDocName As String
Dim stWhere As String

stDocName = "YourReport"
stWhere = "[YourField] =" & Me![YourCorrespondingFormControl]
DoCmd.OpenReport stDocName, acPreview, , stWhere

Err_Exit:
Exit Sub

Err_Handler:
MsgBox Err.Description
Resume Err_Exit

Sprinks

Jody said:
The user needs to be able to print reports from a form and only the report
that correlates to the current record. I am not sure how to do this, any
suggestions would be appreciated. Thanks
 
It worked, thank you so much!

Sprinks said:
Jody,

Sorry you're having trouble. Try:

stWhere = "[LoanLeaseNumber] =" & "'" & Me!LoanLeaseNumber & "'"

Sprinks

Jody said:
I am having a bit of trouble with this, I keep getting this error :

Data type mismatch in critera expression

This is the statement I am using and I would appreciate any help anyone can
give me.
On Error GoTo Err_Handler

Dim stDocName As String
Dim stWhere As String

stDocName = "GAP Worksheet"
stWhere = "[LoanLeaseNumber] =" & Me!LoanLeaseNumber
DoCmd.OpenReport stDocName, acPreview, , stWhere

Err_Exit:
Exit Sub

Err_Handler:
MsgBox Err.Description
Resume Err_Exit


Sprinks said:
Jody,

Use the optional Where clause of the OpenReport method. If you've never
written an event procedure, place a command button in form design view and
show its properties with View, Properties. Click on the Event tab, and click
into the On Click field. An ellipsis will appear on the right-hand side;
click it, and select Code Builder (if necessary--it may not show, depending
on your configuration). Then cut and paste the code below between the
Sub..End Sub lines. Save and exit.

On Error GoTo Err_Handler

Dim stDocName As String
Dim stWhere As String

stDocName = "YourReport"
stWhere = "[YourField] =" & Me![YourCorrespondingFormControl]
DoCmd.OpenReport stDocName, acPreview, , stWhere

Err_Exit:
Exit Sub

Err_Handler:
MsgBox Err.Description
Resume Err_Exit

Sprinks

:

The user needs to be able to print reports from a form and only the report
that correlates to the current record. I am not sure how to do this, any
suggestions would be appreciated. Thanks
 
Back
Top