Discussion Locked

Access 2000 VBA question

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I am creating an Access 2000 form which has a control button on it that when clicked will print a report containing the data from the form. The report is based on a querry. When the querry runs it asks the user to input a specific record # so that it can select only that record and print it in the report. I would like to add some VB code to automate the print button on my form so that when it is clicked it will be able to select the current record # from the form, pass that to the querry, and then print the report using that informaiton and without asking the user which record # to print. Any ideas. Thanks in advance.

3 replies

by chris.lewis

How about something like this:

Private Sub pbPrint_Click()
On Error GoTo Err_pbPrint_Click

DoCmd.OpenReport "rptReport", acViewPreview, , "[idTableID]=" & Me.txtIDOfTable.Value

Exit_pbPrint_Click:
Exit Sub

Err_pbPrint_Click:
MsgBox Err.Description
Resume Exit_pbPrint_Click
End Sub

Where txtIDOfTable is the field holding your record number on the form, and [idTableID] is the table id in the query (Same fields, just diff names here for clarity)

This discussion is closed to new replies.