Bypassing a form's OnOpen event

A

A Marano

I have a form frmPatientSelection with a command button cmdFindPatient, that
opens another form frmPatientEntry using the following code:

Dim TempFilter As String
TempFilter = "[MedicalRecordNum]=" & "'" & Me![txtMedicalRecordNum] &
"'"
DoCmd.OpenForm "frmR1EntryForm", , , TempFilter

where txtMedicalRecordNum is a TextBox that allows the user to enter a
patient's medical record number thereby selecting a patient in
frmPatientEntry.

In frmPatientEntry, I used the OnOpen event to test for whether a patient
with that medical record number actually exists and if not, cause the form
to not open and give an error message:

If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "Please select a valid medical record number, blah, blah
blah."
Cancel = True
End If

This all works fine but my problem is this: I want to add another button
that allows the user to add a brand new patient. But any code I write to do
this runs into frmPatientEntry's OnOpen event which tests for the "no valid
record" condition. How can I somehow put code in the cmdAddNewPatient
button that bypasses frmPatientEntry's OnOpen event code?

Thanks in advance!
 
G

Graham Mandeno

When you use the form to add a new patient, you are presumably specifying
acAdd for the DataMode argument, like this:

DoCmd.OpenForm "frmR1EntryForm", , , , acAdd

This causes the form to open in DataEntry mode, so you can check this in
Form_Open and bail out:

If Me.DataEntry then Exit Sub
 
A

A Marano

That's great Graham. That sounds like that'll solve this problem exactly.

Much thanks!
 
K

Klatuu

Excellent solution Graham. My first thought was to use the OpenArgs and make
the decision in the Load event, but I like your idea much better.

Graham Mandeno said:
When you use the form to add a new patient, you are presumably specifying
acAdd for the DataMode argument, like this:

DoCmd.OpenForm "frmR1EntryForm", , , , acAdd

This causes the form to open in DataEntry mode, so you can check this in
Form_Open and bail out:

If Me.DataEntry then Exit Sub

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

A Marano said:
I have a form frmPatientSelection with a command button cmdFindPatient,
that
opens another form frmPatientEntry using the following code:

Dim TempFilter As String
TempFilter = "[MedicalRecordNum]=" & "'" & Me![txtMedicalRecordNum] &
"'"
DoCmd.OpenForm "frmR1EntryForm", , , TempFilter

where txtMedicalRecordNum is a TextBox that allows the user to enter a
patient's medical record number thereby selecting a patient in
frmPatientEntry.

In frmPatientEntry, I used the OnOpen event to test for whether a patient
with that medical record number actually exists and if not, cause the form
to not open and give an error message:

If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "Please select a valid medical record number, blah, blah
blah."
Cancel = True
End If

This all works fine but my problem is this: I want to add another button
that allows the user to add a brand new patient. But any code I write to
do
this runs into frmPatientEntry's OnOpen event which tests for the "no
valid
record" condition. How can I somehow put code in the cmdAddNewPatient
button that bypasses frmPatientEntry's OnOpen event code?

Thanks in advance!
 
G

Graham Mandeno

Thanks, Klatuu :)

What's your real name, BTW, or do you prefer a cloak of anonymity?

--
Cheers,
Graham M

Klatuu said:
Excellent solution Graham. My first thought was to use the OpenArgs and
make
the decision in the Load event, but I like your idea much better.

Graham Mandeno said:
When you use the form to add a new patient, you are presumably specifying
acAdd for the DataMode argument, like this:

DoCmd.OpenForm "frmR1EntryForm", , , , acAdd

This causes the form to open in DataEntry mode, so you can check this in
Form_Open and bail out:

If Me.DataEntry then Exit Sub

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

A Marano said:
I have a form frmPatientSelection with a command button cmdFindPatient,
that
opens another form frmPatientEntry using the following code:

Dim TempFilter As String
TempFilter = "[MedicalRecordNum]=" & "'" & Me![txtMedicalRecordNum]
&
"'"
DoCmd.OpenForm "frmR1EntryForm", , , TempFilter

where txtMedicalRecordNum is a TextBox that allows the user to enter a
patient's medical record number thereby selecting a patient in
frmPatientEntry.

In frmPatientEntry, I used the OnOpen event to test for whether a
patient
with that medical record number actually exists and if not, cause the
form
to not open and give an error message:

If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "Please select a valid medical record number, blah, blah
blah."
Cancel = True
End If

This all works fine but my problem is this: I want to add another
button
that allows the user to add a brand new patient. But any code I write
to
do
this runs into frmPatientEntry's OnOpen event which tests for the "no
valid
record" condition. How can I somehow put code in the cmdAddNewPatient
button that bypasses frmPatientEntry's OnOpen event code?

Thanks in advance!
 
K

Klatuu

Dave Hargis, Fort Worth, Texas

Graham Mandeno said:
Thanks, Klatuu :)

What's your real name, BTW, or do you prefer a cloak of anonymity?

--
Cheers,
Graham M

Klatuu said:
Excellent solution Graham. My first thought was to use the OpenArgs and
make
the decision in the Load event, but I like your idea much better.

Graham Mandeno said:
When you use the form to add a new patient, you are presumably specifying
acAdd for the DataMode argument, like this:

DoCmd.OpenForm "frmR1EntryForm", , , , acAdd

This causes the form to open in DataEntry mode, so you can check this in
Form_Open and bail out:

If Me.DataEntry then Exit Sub

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

"A Marano" <april dot marano at gte dot net> wrote in message
I have a form frmPatientSelection with a command button cmdFindPatient,
that
opens another form frmPatientEntry using the following code:

Dim TempFilter As String
TempFilter = "[MedicalRecordNum]=" & "'" & Me![txtMedicalRecordNum]
&
"'"
DoCmd.OpenForm "frmR1EntryForm", , , TempFilter

where txtMedicalRecordNum is a TextBox that allows the user to enter a
patient's medical record number thereby selecting a patient in
frmPatientEntry.

In frmPatientEntry, I used the OnOpen event to test for whether a
patient
with that medical record number actually exists and if not, cause the
form
to not open and give an error message:

If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "Please select a valid medical record number, blah, blah
blah."
Cancel = True
End If

This all works fine but my problem is this: I want to add another
button
that allows the user to add a brand new patient. But any code I write
to
do
this runs into frmPatientEntry's OnOpen event which tests for the "no
valid
record" condition. How can I somehow put code in the cmdAddNewPatient
button that bypasses frmPatientEntry's OnOpen event code?

Thanks in advance!
 

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