Syntax to refer to a control on a subform.

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

Guest

Hi, I have (below) some code that opens a form(FrmRecUpdate) based on the
selected PatientNo in another form called FrmClinic1sub.

'DoCmd.OpenForm "FrmRecUpdate", , , "[PatientNo] =
Forms![FrmClinic1Sub]![PatientNo]"

This works fine when the form FrmClinic1Sub is opened as a standalone form.
However it needs to open as a Subform, contained within a form called
FrmClinic1. When I amend the code to account for the fact that FrmClinic1Sub
is now a subform, it fails. My new code is partly derived from the help
screen, and from the original code, suggested by Rowiga

DoCmd.OpenForm "FrmRecUpdate", , , "PatientNo =
Forms!FrmClinic1.FrmClinic1sub.Form!Controls.PatientNo"

Am I making a mistake, or is this action not possible from a subfrom?

Thank you, Tim
 
It is possible.

If the code is in the context of FrmClinic1Sub and [PatientNo] is a numeric
Field or a Control bound to a numeric Field, use:

DoCmd.OpenForm "FrmRecUpdate", , , "[PatientNo] = " & Me.[PatientNo]
 
Van T.

Thank you, will try this later today, and thank you for your other post too.
Does the code below only work on numerical fields, as the PatientNo is
actually text, since the patient number, although a number also has the first
initials of the hospital infront.

Thank you Tim.


Van T. Dinh said:
It is possible.

If the code is in the context of FrmClinic1Sub and [PatientNo] is a numeric
Field or a Control bound to a numeric Field, use:

DoCmd.OpenForm "FrmRecUpdate", , , "[PatientNo] = " & Me.[PatientNo]

--
HTH
Van T. Dinh
MVP (Access)




Timboo said:
Hi, I have (below) some code that opens a form(FrmRecUpdate) based on the
selected PatientNo in another form called FrmClinic1sub.

'DoCmd.OpenForm "FrmRecUpdate", , , "[PatientNo] =
Forms![FrmClinic1Sub]![PatientNo]"

This works fine when the form FrmClinic1Sub is opened as a standalone form.
However it needs to open as a Subform, contained within a form called
FrmClinic1. When I amend the code to account for the fact that FrmClinic1Sub
is now a subform, it fails. My new code is partly derived from the help
screen, and from the original code, suggested by Rowiga

DoCmd.OpenForm "FrmRecUpdate", , , "PatientNo =
Forms!FrmClinic1.FrmClinic1sub.Form!Controls.PatientNo"

Am I making a mistake, or is this action not possible from a subfrom?

Thank you, Tim
 
If it is Text, you need to use:

DoCmd.OpenForm "FrmRecUpdate", , , _
"[PatientNo] = '" & Me.[PatientNo] & "'"
 
Back
Top