Printing a single record from a form in a report help

jbeling

Registered User.
Local time
Today, 06:58
Joined
Nov 28, 2008
Messages
28
This is my event procedure and when i click the button it prompts me to input the "ID" which is the primary key of the record I want to print. How do I make it so it just automatically uses the ID that is on the form?


Private Sub cmdPrintRecord_Click()
Dim strReportName As String
Dim strCriteria As String

strReportName = "rptPrintRecord"
strCriteria = "[ID]='" & Me![ID] & "'"
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria


End Sub
 
i tried this too but still wouldnt work

Private Sub cmdPrintRecord_Click()

Dim strDocName As String
Dim strWhere As String
strDocName = "rptPrintRecord"
strWhere = "[ID]=" & Me!ID
DoCmd.OpenReport strDocName, acPreview, , strWhere
On Error GoTo Err_Print_Click
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.PrintOut acSelection
Exit_Print_Click:
Exit Sub
Err_Print_Click:
MsgBox Err.Description
Resume Exit_Print_Click

End Sub
 
Howzit

just tried this on mine - it worked

My invoiceid is a number

Code:
Private Sub cmdTest_Click()
On Error GoTo Err_cmdTest_Click

    Dim stDocName As String
    Dim strWhere As String
    
       strWhere = "[Invoiceid]=" & Me.InvoiceID

    stDocName = "testinvoice"
    DoCmd.OpenReport stDocName, acPreview, , strWhere

Exit_cmdTest_Click:
    Exit Sub

Err_cmdTest_Click:
    MsgBox Err.Description
    Resume Exit_cmdTest_Click
    
End Sub
 
Ok I got it to work. The code was right. The report was messed up. Here is my question. How can I add an update command to the below code that I am using for that button. I guess the form needs to update before I do print preview.



Private Sub cmdPrintRecord_Click()

On Error GoTo Err_cmdPrintRecord_Click
Dim stDocName As String
Dim strWhere As String

strWhere = "[ID]=" & Me.ID
stDocName = "rptPrintRecord"
DoCmd.OpenReport stDocName, acPreview, , strWhere
Exit_cmdPrintRecord_Click:
Exit Sub
Err_cmdPrintRecord_Click:
MsgBox Err.Description
Resume Exit_cmdPrintRecord_Click



End Sub
 
If you mean save the record:

DoCmd.RunCommand acCmdSaveRecord
 
At whatever point you want to force the record to save. Based on what you said, anywhere before the OpenReport line in your code above. Actually, probably before the line where you set strWhere, in case that value is dependent on the save.
 

Users who are viewing this thread

Back
Top Bottom