Open form command with where clause

  • Thread starter Thread starter Rob
  • Start date Start date
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
 
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] & "'"
 
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
 
Back
Top