Command Button question

R

R. Stiles

I need to put a command button on a For to open/print a Report that has a
query as the Data Source using the current record that is in the form when
the button is pressed. Seemed like it would be a simple operation but it
totally escapes me.

i.e.
DoButton on SearchForm opens MissionReport based on SearchQuery using the
current record on SearchForm.
 
A

Allen Browne

Try this [Event Procedure] for your command button:

Private Sub DoButton_Click()
Dim strWhere As String
If Me.Dirty Then 'Save any changes.
Me.Dirty = False
End If
If Me.NewRecord Then
MsgBox "Select a record to print."
Else
strWhere = "[ID] = " & Me.ID
DoCmd.OpenReport "MissionReport", acViewPreview,, strWhere
End If
End Sub

That assumes there is a primary key (number) field named "ID" that can be
used to uniquely identify the record in the form.
 
Top