Button which refreshes form and opens a report


G

Guest

I have a form which has a button which opens a report.
I want to make the button refresh and then open the report.

Thanks.

The code for the button is:

Private Sub cmdOpCOBas_Click()
On Error GoTo Err_cmdOpCOBas_Click

Dim stDocName As String
Dim strWhere As String
strWhere = "[FVF#] = '" & Me.[FVF#] & "' AND Trade='" & Me.Trade & "'
AND [Change#]= " & Me.[Change#] & "AND Revision='" & Me.Revision & "'"
stDocName = "rptChOrdBasic1"

DoCmd.OpenReport stDocName, acPreview, , strWhere

Exit_cmdOpCOBas_Click:
Exit Sub

Err_cmdOpCOBas_Click:
MsgBox Err.Description
Resume Exit_cmdOpCOBas_Click

End Sub
 
Ad

Advertisements

R

Rick B

Here is the code I use. You can copy and paste the first part that deals
with saving the record...


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 "MyReport", acViewPreview, , strWhere

End If



End Sub



Notes: If your primary key is a Text type field (not a Number type field),
you need extra quotes: strWhere = "[ID] = """ & Me.[ID] & """"

If you want the report to print without preview, replace acViewPreview with
acViewNormal.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top