Open form to specific record

J

Jerry Anderson

I have a control button that opens another form and displays a specific
record based upon linked fields; its functionality was coded via the Control
Wizard. My problem: I need to open another form and display a specific
record, but based on not one, but two fields.
The original form is "Special Events", and it contains two fields, "Event"
and "Cost Center". How do I open the new form and display the records that
share the same values as these two? Is it possible to specify not one
parameter, but two and open another form? Does someone have a code snippet?
I do love these forums!
Thanks!
 
N

NKTower

Private Sub cmdTheButton_Click()
Dim str_Where As String

str_Where = "( ( [Evemt] = " & Me.Event & " ) AND [CostCenter] = " &
Me.CostCenter & " ) )"

DoCmd.OpenForm "theForm",acNormal,,str_Where
End Sub

Some notes:
a) If Event or CostCenter is character field, you will have to put quotes in
- hard to show here.
b) That str_Where = line is ONE line, it may wrap in here
c) Note the TWO commas ahead of the str_Where in the DoCmd line. That's to
skip over the FILTER argument - which we aren't using.
 
K

Klatuu

The parenthises are not required and the OP should be aware the coding assumes
Event and CostCenter are both numeric fields. If it is the case they are
text, it would be:
str_Where = "[Event] = """ & Me.Event & """ AND [CostCenter] = """ &
Me.CostCenter & """"

--
Dave Hargis, Microsoft Access MVP


NKTower said:
Private Sub cmdTheButton_Click()
Dim str_Where As String

str_Where = "( ( [Evemt] = " & Me.Event & " ) AND [CostCenter] = " &
Me.CostCenter & " ) )"

DoCmd.OpenForm "theForm",acNormal,,str_Where
End Sub

Some notes:
a) If Event or CostCenter is character field, you will have to put quotes in
- hard to show here.
b) That str_Where = line is ONE line, it may wrap in here
c) Note the TWO commas ahead of the str_Where in the DoCmd line. That's to
skip over the FILTER argument - which we aren't using.


Jerry Anderson said:
I have a control button that opens another form and displays a specific
record based upon linked fields; its functionality was coded via the Control
Wizard. My problem: I need to open another form and display a specific
record, but based on not one, but two fields.
The original form is "Special Events", and it contains two fields, "Event"
and "Cost Center". How do I open the new form and display the records that
share the same values as these two? Is it possible to specify not one
parameter, but two and open another form? Does someone have a code snippet?
I do love these forums!
Thanks!
 

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