G
Guest
Need a Print and Close Command to be use in some Access Unbound Forms.
Rick - Can't seem to get to post here any other way - hope you see this. Am
trying to create a command button on a data entry form that once I have
filled in the data, I can click on and it will print JUST that record on
another form in the DB. HELP!
John - yes - absolutely all is stored in tables, no transient data. I can
get it to print a report, but it tries to print all 806 records, not just the
currently selected record
John Vinson said:John - yes - absolutely all is stored in tables, no transient data. I can
get it to print a report, but it tries to print all 806 records, not just the
currently selected record
Two options:
1. Base the Report on a Query which references a control on the form
as a criterion, using the syntax
=[Forms]![YourFormName]![YourControlName]
2. Edit the wizard-generated OpenReport code in the click event to
include a WhereCondition. It should have a line like
stCriteria = ""
Edit this to something like
stCriteria = "[ID] = " & Me.txtID
using your own field and control names.
John W. Vinson[MVP]
I entered the following code for the command button:
Private Sub CitationPrintPreview_Click()
Dim strReportName As String
Dim strCriterea As String
If NewRecord Then
MsgBox "This record contains no data. Please select a record to
print or Save this record.", vbInformation, "Invalid Action"
Exit Sub
Else
strReportName = "Citation"
strCriterea = "[Cite_#]= " & Me![Cite_#]
'strCriterea = "[Cite_#]='" & Me![Cite_#] & "'"
DoCmd.OpenReport strReportName, acViewPreview, , strCriterea
End If
End Sub
It's the closest I have gotten to success so far, however, when I execute
it, I am presented with the error message that says:
John Vinson said:I entered the following code for the command button:
Private Sub CitationPrintPreview_Click()
Dim strReportName As String
Dim strCriterea As String
If NewRecord Then
MsgBox "This record contains no data. Please select a record to
print or Save this record.", vbInformation, "Invalid Action"
Exit Sub
Else
strReportName = "Citation"
strCriterea = "[Cite_#]= " & Me![Cite_#]
This will work only if the [Cite_#] field is numeric. Looking at the
examples below it's clear that it's not.
'strCriterea = "[Cite_#]='" & Me![Cite_#] & "'"
This *should* work - just put a ' before the strCriteria on the line
above and remove the ' in front of this one. Does that do the job for
you?
DoCmd.OpenReport strReportName, acViewPreview, , strCriterea
End If
End Sub
It's the closest I have gotten to success so far, however, when I execute
it, I am presented with the error message that says:
John W. Vinson[MVP]
John Vinson said:I entered the following code for the command button:
Private Sub CitationPrintPreview_Click()
Dim strReportName As String
Dim strCriterea As String
If NewRecord Then
MsgBox "This record contains no data. Please select a record to
print or Save this record.", vbInformation, "Invalid Action"
Exit Sub
Else
strReportName = "Citation"
strCriterea = "[Cite_#]= " & Me![Cite_#]
This will work only if the [Cite_#] field is numeric. Looking at the
examples below it's clear that it's not.
'strCriterea = "[Cite_#]='" & Me![Cite_#] & "'"
This *should* work - just put a ' before the strCriteria on the line
above and remove the ' in front of this one. Does that do the job for
you?
DoCmd.OpenReport strReportName, acViewPreview, , strCriterea
End If
End Sub
It's the closest I have gotten to success so far, however, when I execute
it, I am presented with the error message that says:
John W. Vinson[MVP]
Closer, but still not it. The code now looks like:
John Vinson said:Closer, but still not it. The code now looks like:
The code should be:
Private Sub CitationPrintPreview_Click()
Dim strReportName As String
Dim strCriterea As String
If NewRecord Then
MsgBox "This record contains no data. Please select a record
to
print or Save this record.", vbInformation, "Invalid Action"
Exit Sub
Else
strReportName = "Citation"
strCriterea = "[Cite_#]='" & Me![Cite_#] & "'"
DoCmd.OpenReport strReportName, acViewPreview, , strCriterea
End If
End Sub
if I understand your structure correctly. Bear in mind: I cannot see
your database. I do not know anything about your form or your table
structure, so I cannot be *sure* that opening the report and selecting
the value of the form control [Cite_#] will get the correct record or
records - but the above is the proper syntax if that is what you want
to do.
John W. Vinson[MVP]