Question : command box on my form that when clicked sends my report as .pdf file but in wrong record

Hello Experts,

I have a command button on my form that when clicked opens my report as .pdf file. I'm using Access 2003.

The problem is that if my form is in record 8 and I click the command button, it will open my report to record 1 instead of record 8 like I need it to be.

I have the following code in this command button on click event, can this code be altered so it will open my report to the correct record 8 so the report will show the same data as the form did?

The form and the report both use the same data source table and the primary key is invoice#,
Both the report and form have the same name Contract.

Code that is in the command button onclick event.

blRet = ConvertReportToPDF("Contract", vbNullString, "Contract.pdf", False, True, 150, "", "", 0, 0, 0)

Any help w/be greatly appreciated.

Thanks
patentinv

Answer : command box on my form that when clicked sends my report as .pdf file but in wrong record

In the recorsource of your report, you can add a function call to filter what it is displaying to match your selection from the form. To do this, under ContractID in the recordsource query of the report add:

IIF(fnContract()=0,[ContractID],fnContractID())

Change ContractID to whatever you have in your actual query.

Also, in a module have:

Function fnContractID() As Variant
On Error GoTo 10

Dim ValueFromTheForm As Variant

ValueFromTheForm=Nz(Forms!EnterYouFormNameHear!txtContactIDselected,0)
' change EnterYouFormNameHear and txtContactIDselected to whatever you have on your form

Debug.Print ValueFromTheForm 'make sure this value is reported correctly then remove this line

fnContractID = ValueFromTheForm

Exit Function

10:

fnContractID = 0

End Function

Mike

Random Solutions  
 
programming4us programming4us