Newbie: How to preview a report of a record selected in a form

F

Frank Krogh

Problem I:
I have made a form to display and edit the fields of a selected record. I
have added a combobox with three columns (included a hidden PK) to select a
record.

When a row is selected in the combobox, the combobox only shows the value
from one of the two displayed columns.

How do I make the combobox display values in both columns after the
selection?


Problem II:
In the form I have also added a command button that opens a report preview.

How can I make the report preview display the selected record and not all
the records in the table?


Thanks for suggestions


Frank Krogh
 
A

Allen Browne

A1: Combo
Use a query as the RowSource of the combo.
In query design, concatenate the two fields together.
For example, you might type this into the Field row of the query:
FullName: [FirstName] & " " & [Surname]

Alternatively, you can place a text box alongside the combo, and show the
value from the 3rd column by putting this into the ControlSource of the text
box:
=[MyCombo].Column(2)
Note that the first column is number zero.

A2: Print This Record button
This code assumes a primary key named "ID":

Private Sub cmdPrint_Click()
If Me.Dirty Then
Me.Dirty = False
End If
If Me.NewRecord Then
Beep
Else
DoCmd.OpenReport "MyReport", acViewPreview, , "ID = " & Me.ID
End If
End Sub
 

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