cacorley
12-11-2009, 11:20 AM
I can't seem to get my print command to work. I'm using Access 2007 and have set-up a form with a cmdPrint button, with an event procedure, and a report. The code for the procedure is below. When I click on the button, basically nothing happens. Any ideas?
Private Sub cmdPrint_Click()
Dim strWhere As String
If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If
If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[ID] = " & Me.[ID]
DoCmd.OpenReport "Order_Summary", acViewPreview, , strWhere
End If
End Sub
boblarson
12-11-2009, 11:25 AM
Is the ID field text or numeric? Also, is the ID field in the report's recordsource?
If text:
strWhere = "[ID] = " & Chr(34) & Me!ID & Chr(34)
If numeric:
strWhere = "[ID] = " & Me!ID
I would probably use the bang in this instance so you are making sure that the current field is selected. If your text box that holds ID on the form is named ID I would change it to txtID and then you can use
strWhere = "[ID] = " & Me.txtID
cacorley
12-11-2009, 01:09 PM
Thank you for the advice. I tried the different suggestions you made, but still nothing.
1) The report recordsource contains both ID (numeric) and Order_No (text) which are unique. I've tried using each and still cannot get the procedure to work.
I have a subdatasheet on the form. Will that make a difference?
boblarson
12-11-2009, 01:28 PM
I have a subdatasheet on the form. Will that make a difference?
It shouldn't if the record selected is on the main form. Can you perhaps post a copy of your database (with any sensitive data deleted or scrambled)?
cacorley
12-14-2009, 05:44 AM
Sorry for the late reply. I was busy all weekend. I have uploaded a copy of my database. Nothing classified - just some sample information I'm using to set-up the database. The form is "Order" and the report is also name "Order" where I would like only a specific record displayed on the report from the form.
boblarson
12-14-2009, 07:49 AM
As it is 2007 format, I'll have to wait until I get home tonight as I don't have 2007 here at work.