Open form command with where clause

R

Rob

I want to open a form to add a record based on what the user chose in the
previous form

The documentation says I should do this:
To open a form and restrict its records to those specified by the value of a
control on another form, use the following expression:
[fieldname] = Forms![formname]![controlname on other form]

My code is:
DoCmd.OpenForm "Forms!frmPhase", , , [tblPhase.PhaseID] =
Forms![frmPhaseSearch]![CboPhase]

It doesn't work. The value of the highlighted section of
Forms![frmPhaseSearch]![CboPhase] changes properly but for some reason the
line is wrong somehow.

What is the error?

Thanks in advance,

Rob
 
P

PC Datasheet

Your where clause needs to be a string --

"[tblPhase.PhaseID] = " & Forms![frmPhaseSearch]![CboPhase]

The above assumes PhaseID is numeric. If it is a string, use:

"[tblPhase.PhaseID] = '" & Forms![frmPhaseSearch]![CboPhase] & "'"
 
R

Rob

I see. That works
Thank you very much.

Rob


PC Datasheet said:
Your where clause needs to be a string --

"[tblPhase.PhaseID] = " & Forms![frmPhaseSearch]![CboPhase]

The above assumes PhaseID is numeric. If it is a string, use:

"[tblPhase.PhaseID] = '" & Forms![frmPhaseSearch]![CboPhase] & "'"


--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
(e-mail address removed)
www.pcdatasheet.com


Rob said:
I want to open a form to add a record based on what the user chose in the
previous form

The documentation says I should do this:
To open a form and restrict its records to those specified by the value of a
control on another form, use the following expression:
[fieldname] = Forms![formname]![controlname on other form]

My code is:
DoCmd.OpenForm "Forms!frmPhase", , , [tblPhase.PhaseID] =
Forms![frmPhaseSearch]![CboPhase]

It doesn't work. The value of the highlighted section of
Forms![frmPhaseSearch]![CboPhase] changes properly but for some reason the
line is wrong somehow.

What is the error?

Thanks in advance,

Rob
 

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