Print current selected record to a report

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

Guest

I need to print olny the current selected record on my form to a report. I'm
using the following code:

Private Sub cmdPrintCurrentFA_Click()
On Error GoTo Err_cmdPrintCurrentReport_Click

Dim stDocName As String
Dim stWhere As String

stDocName = "rptFinancialAssesment"

DoCmd.OpenReport "rptFinancialAssesment", , ,
"[infSSN]=Forms!frmFinancialAssesment!infSSN"

Exit_cmdPrintCurrentReport_Click:
Exit Sub

Err_cmdPrintCurrentReport_Click:
MsgBox Err.Description
Resume Exit_cmdPrintCurrentReport_Click
End Sub
---
When I print it prompts me for input. the msg box says
"Forms!frmFinancialAssesment!infSSN"
I'm guessing it want me to input the infSSN (social security number, which
is the primary key) Any way i can just get it to print the report for the
current selected record without inputing anything?
 
If the record field "infSSN" isn't referenced as the data source
of one of the reports controls, it isn't accessible in code.
Sometimes, one has to included an invisible control on their
reports with the desired record field as its data source.

Bill
 
Can you confirm or deny that your current form is named
"frmFinancialAssesment"? I would expect the SSN to be stored in a text field
on the current form. This would make your

Private Sub cmdPrintCurrentFA_Click()
On Error GoTo Err_cmdPrintCurrentReport_Click

Dim stDocName As String
Dim stWhere As String

stDocName = "rptFinancialAssesment"
stWhere = "infSSN ='" & Me.infSSN & "'"

DoCmd.OpenReport "rptFinancialAssesment", , , strWhere

Exit_cmdPrintCurrentReport_Click:
Exit Sub

Err_cmdPrintCurrentReport_Click:
MsgBox Err.Description
Resume Exit_cmdPrintCurrentReport_Click
End Sub
 
Yes the current form is named frmFinancialAssesment. infSSN is stored in a
text field on the current form. infSSN is the primary key on the table
related to this form as well as one other. The code you provided eliminated
the msgbox prompt for input, but it still prints all records in the database,
not just the current one.

Duane Hookom said:
Can you confirm or deny that your current form is named
"frmFinancialAssesment"? I would expect the SSN to be stored in a text field
on the current form. This would make your

Private Sub cmdPrintCurrentFA_Click()
On Error GoTo Err_cmdPrintCurrentReport_Click

Dim stDocName As String
Dim stWhere As String

stDocName = "rptFinancialAssesment"
stWhere = "infSSN ='" & Me.infSSN & "'"

DoCmd.OpenReport "rptFinancialAssesment", , , strWhere

Exit_cmdPrintCurrentReport_Click:
Exit Sub

Err_cmdPrintCurrentReport_Click:
MsgBox Err.Description
Resume Exit_cmdPrintCurrentReport_Click
End Sub

--
Duane Hookom
Microsoft Access MVP


robertm600635 said:
I need to print olny the current selected record on my form to a report. I'm
using the following code:

Private Sub cmdPrintCurrentFA_Click()
On Error GoTo Err_cmdPrintCurrentReport_Click

Dim stDocName As String
Dim stWhere As String

stDocName = "rptFinancialAssesment"

DoCmd.OpenReport "rptFinancialAssesment", , ,
"[infSSN]=Forms!frmFinancialAssesment!infSSN"

Exit_cmdPrintCurrentReport_Click:
Exit Sub

Err_cmdPrintCurrentReport_Click:
MsgBox Err.Description
Resume Exit_cmdPrintCurrentReport_Click
End Sub
---
When I print it prompts me for input. the msg box says
"Forms!frmFinancialAssesment!infSSN"
I'm guessing it want me to input the infSSN (social security number, which
is the primary key) Any way i can just get it to print the report for the
current selected record without inputing anything?
 
infSSN is on the report as a text box, with the field infSSN as the control
source.

Bill said:
If the record field "infSSN" isn't referenced as the data source
of one of the reports controls, it isn't accessible in code.
Sometimes, one has to included an invisible control on their
reports with the desired record field as its data source.

Bill


robertm600635 said:
I need to print olny the current selected record on my form to a report.
I'm
using the following code:

Private Sub cmdPrintCurrentFA_Click()
On Error GoTo Err_cmdPrintCurrentReport_Click

Dim stDocName As String
Dim stWhere As String

stDocName = "rptFinancialAssesment"

DoCmd.OpenReport "rptFinancialAssesment", , ,
"[infSSN]=Forms!frmFinancialAssesment!infSSN"

Exit_cmdPrintCurrentReport_Click:
Exit Sub

Err_cmdPrintCurrentReport_Click:
MsgBox Err.Description
Resume Exit_cmdPrintCurrentReport_Click
End Sub
---
When I print it prompts me for input. the msg box says
"Forms!frmFinancialAssesment!infSSN"
I'm guessing it want me to input the infSSN (social security number, which
is the primary key) Any way i can just get it to print the report for the
current selected record without inputing anything?
 
Ok, I got it printing out the current record ok now, but it won't print out
all the fields. Only about half the fields where I entered data are printing
out, the rest are just blank. I used the code you posted for me.

Duane Hookom said:
Can you confirm or deny that your current form is named
"frmFinancialAssesment"? I would expect the SSN to be stored in a text field
on the current form. This would make your

Private Sub cmdPrintCurrentFA_Click()
On Error GoTo Err_cmdPrintCurrentReport_Click

Dim stDocName As String
Dim stWhere As String

stDocName = "rptFinancialAssesment"
stWhere = "infSSN ='" & Me.infSSN & "'"

DoCmd.OpenReport "rptFinancialAssesment", , , strWhere

Exit_cmdPrintCurrentReport_Click:
Exit Sub

Err_cmdPrintCurrentReport_Click:
MsgBox Err.Description
Resume Exit_cmdPrintCurrentReport_Click
End Sub

--
Duane Hookom
Microsoft Access MVP


robertm600635 said:
I need to print olny the current selected record on my form to a report. I'm
using the following code:

Private Sub cmdPrintCurrentFA_Click()
On Error GoTo Err_cmdPrintCurrentReport_Click

Dim stDocName As String
Dim stWhere As String

stDocName = "rptFinancialAssesment"

DoCmd.OpenReport "rptFinancialAssesment", , ,
"[infSSN]=Forms!frmFinancialAssesment!infSSN"

Exit_cmdPrintCurrentReport_Click:
Exit Sub

Err_cmdPrintCurrentReport_Click:
MsgBox Err.Description
Resume Exit_cmdPrintCurrentReport_Click
End Sub
---
When I print it prompts me for input. the msg box says
"Forms!frmFinancialAssesment!infSSN"
I'm guessing it want me to input the infSSN (social security number, which
is the primary key) Any way i can just get it to print the report for the
current selected record without inputing anything?
 
If this is a new record, it is possible the record hasn't been saved yet
which would result in values not displaying in the report. You can a line of
code like:

Me.Dirty = False
stDocName = "rptFinancialAssesment"
stWhere = "infSSN ='" & Me.infSSN & "'"

DoCmd.OpenReport "rptFinancialAssesment", , , strWhere


--
Duane Hookom
Microsoft Access MVP


robertm600635 said:
Ok, I got it printing out the current record ok now, but it won't print out
all the fields. Only about half the fields where I entered data are printing
out, the rest are just blank. I used the code you posted for me.

Duane Hookom said:
Can you confirm or deny that your current form is named
"frmFinancialAssesment"? I would expect the SSN to be stored in a text field
on the current form. This would make your

Private Sub cmdPrintCurrentFA_Click()
On Error GoTo Err_cmdPrintCurrentReport_Click

Dim stDocName As String
Dim stWhere As String

stDocName = "rptFinancialAssesment"
stWhere = "infSSN ='" & Me.infSSN & "'"

DoCmd.OpenReport "rptFinancialAssesment", , , strWhere

Exit_cmdPrintCurrentReport_Click:
Exit Sub

Err_cmdPrintCurrentReport_Click:
MsgBox Err.Description
Resume Exit_cmdPrintCurrentReport_Click
End Sub

--
Duane Hookom
Microsoft Access MVP


robertm600635 said:
I need to print olny the current selected record on my form to a report. I'm
using the following code:

Private Sub cmdPrintCurrentFA_Click()
On Error GoTo Err_cmdPrintCurrentReport_Click

Dim stDocName As String
Dim stWhere As String

stDocName = "rptFinancialAssesment"

DoCmd.OpenReport "rptFinancialAssesment", , ,
"[infSSN]=Forms!frmFinancialAssesment!infSSN"

Exit_cmdPrintCurrentReport_Click:
Exit Sub

Err_cmdPrintCurrentReport_Click:
MsgBox Err.Description
Resume Exit_cmdPrintCurrentReport_Click
End Sub
---
When I print it prompts me for input. the msg box says
"Forms!frmFinancialAssesment!infSSN"
I'm guessing it want me to input the infSSN (social security number, which
is the primary key) Any way i can just get it to print the report for the
current selected record without inputing anything?
 
Back
Top