Exporting single record from a FORM to PDF

GraemeG

Registered User.
Local time
Today, 20:28
Joined
Jan 22, 2011
Messages
212
Hello.

I am having trouble exporting single records from a form to pdf.
I have the following code so far. but it gives:

Run time error 3464
Data type mismatch in criteria expression.

Debug highlights:
Me.RecordSource = "Select * From Propertyextract Where [propref] = " & _
![propref]

Any help appreciated.

Code:
Private Sub cmdExportPDF_Click()
 Dim MyDB As DAO.Database
    Dim MyRS As DAO.Recordset
    Dim strSQL As String
 
 
    strSQL = "Select Propertyextract.[propref] From Propertyextract;"
 
    Set MyDB = CurrentDb
    Set MyRS = MyDB.OpenRecordset(strSQL, dbOpenForwardOnly)
 
    With MyRS
      Do While Not MyRS.EOF
        Me.RecordSource = "Select * From Propertyextract Where [propref] = " & _
                           ![propref]
        DoCmd.OutputTo acOutputForm, "FrmPropertyAttributes", acFormatPDF, "" & ![propref] & ".pdf"
         .MoveNext
      Loop
    End With
 
 
    MyRS.Close
    Set MyRS = Nothing
End Sub
 
is propref a number or a string?

The data is a number but design is text.
however the propref may contain a letter at the end in some cases but not yet.
 
So let me get this right. You open a form with a varying amount of records as its recordsoure. Then at a click of a button you want to print a pdf for each underlying record in the record source. Is this correct?
 
So let me get this right. You open a form with a varying amount of records as its recordsoure. Then at a click of a button you want to print a pdf for each underlying record in the record source. Is this correct?

Yes the form opens up with full recordset. But I just want to export 'Current Selected Record' within the form to a PDF via a button.
 
Last edited:
Then you need to create a report. You don't normally print forms. Create your report and use the ExportToPDF
 

Users who are viewing this thread

Back
Top Bottom