Command Button question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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.
 

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

Back
Top