Review values in subform before closing main form

G

Guest

Hello there,

I would like to add an statement to the close button on a main form that
prevents the main form from closing if there are values in the NAME field of
a subform. The subform is a datasheet form, so I can see several lines of
data. The idea is that the user would only be able to close the main form if
there are no values at all in the NAME field of the subform. Ideas?

Thanks!

alepag
 
G

Guest

You could use the forms Unload event to trap for this. The code might look
something like;

Private Sub Form_Unload(Cancel As Integer)

If Not IsNull (Me!NameOfSubform.Form!NameOfSubformControl) Then

Cancel = True
Me![SomeControl].SetFocus

End If

End Sub

If you want to allow a zero length string in the field then you would modify
it like;

If Not IsNull (Me!NameOfSubform.Form!NameOfSubformControl) OR _
Me!NameOfSubform.Form!NameOfSubformControl <> "" Then

Cancel = True
Me![SomeControl].SetFocus

End If

End Sub

HTH
 
G

Guest

Hello Beetle,

Thanks for the advice. However, that's pretty much what I did, and it didn't
work. Here's my code:

If Not IsNull(Forms!sfrm_Pts_Queue_Or_InProcess!PATIENT_NAME) Then
MsgBox "There are patients still being admitted"
DoCmd.CancelEvent
Else
DoCmd.Close
End If

Do you see anything wrong with that code?

Thanks!

Beetle said:
You could use the forms Unload event to trap for this. The code might look
something like;

Private Sub Form_Unload(Cancel As Integer)

If Not IsNull (Me!NameOfSubform.Form!NameOfSubformControl) Then

Cancel = True
Me![SomeControl].SetFocus

End If

End Sub

If you want to allow a zero length string in the field then you would modify
it like;

If Not IsNull (Me!NameOfSubform.Form!NameOfSubformControl) OR _
Me!NameOfSubform.Form!NameOfSubformControl <> "" Then

Cancel = True
Me![SomeControl].SetFocus

End If

End Sub

HTH

--
_________

Sean Bailey


Alejandro said:
Hello there,

I would like to add an statement to the close button on a main form that
prevents the main form from closing if there are values in the NAME field of
a subform. The subform is a datasheet form, so I can see several lines of
data. The idea is that the user would only be able to close the main form if
there are no values at all in the NAME field of the subform. Ideas?

Thanks!

alepag
 
G

Guest

I forgot to tell you: when I try to use the close button, I get the following
message:

"Microsfot Office Access can't find the form "sfrm_Pts_Queue_Or_InProcess"
referred to in a macro expression or Visual Basic code".

It seems that Access can't find the subform within the main form...I can't
figure out what's wrong here.

Thanks again!


Alejandro said:
Hello Beetle,

Thanks for the advice. However, that's pretty much what I did, and it didn't
work. Here's my code:

If Not IsNull(Forms!sfrm_Pts_Queue_Or_InProcess!PATIENT_NAME) Then
MsgBox "There are patients still being admitted"
DoCmd.CancelEvent
Else
DoCmd.Close
End If

Do you see anything wrong with that code?

Thanks!

Beetle said:
You could use the forms Unload event to trap for this. The code might look
something like;

Private Sub Form_Unload(Cancel As Integer)

If Not IsNull (Me!NameOfSubform.Form!NameOfSubformControl) Then

Cancel = True
Me![SomeControl].SetFocus

End If

End Sub

If you want to allow a zero length string in the field then you would modify
it like;

If Not IsNull (Me!NameOfSubform.Form!NameOfSubformControl) OR _
Me!NameOfSubform.Form!NameOfSubformControl <> "" Then

Cancel = True
Me![SomeControl].SetFocus

End If

End Sub

HTH

--
_________

Sean Bailey


Alejandro said:
Hello there,

I would like to add an statement to the close button on a main form that
prevents the main form from closing if there are values in the NAME field of
a subform. The subform is a datasheet form, so I can see several lines of
data. The idea is that the user would only be able to close the main form if
there are no values at all in the NAME field of the subform. Ideas?

Thanks!

alepag
 
G

Guest

Try using the following method to refer to the subform in your code;

(Me!sfrm_Pts_Queue_Or_InProcess.Form!PATIENT_NAME)

So it's Name of the main form (Me), Name of the subform control, then the
name of the control within the subform. Notice the extra .Form after the
subform name but before the control name. It won't work without this.

HTH
--
_________

Sean Bailey


Alejandro said:
I forgot to tell you: when I try to use the close button, I get the following
message:

"Microsfot Office Access can't find the form "sfrm_Pts_Queue_Or_InProcess"
referred to in a macro expression or Visual Basic code".

It seems that Access can't find the subform within the main form...I can't
figure out what's wrong here.

Thanks again!


Alejandro said:
Hello Beetle,

Thanks for the advice. However, that's pretty much what I did, and it didn't
work. Here's my code:

If Not IsNull(Forms!sfrm_Pts_Queue_Or_InProcess!PATIENT_NAME) Then
MsgBox "There are patients still being admitted"
DoCmd.CancelEvent
Else
DoCmd.Close
End If

Do you see anything wrong with that code?

Thanks!

Beetle said:
You could use the forms Unload event to trap for this. The code might look
something like;

Private Sub Form_Unload(Cancel As Integer)

If Not IsNull (Me!NameOfSubform.Form!NameOfSubformControl) Then

Cancel = True
Me![SomeControl].SetFocus

End If

End Sub

If you want to allow a zero length string in the field then you would modify
it like;

If Not IsNull (Me!NameOfSubform.Form!NameOfSubformControl) OR _
Me!NameOfSubform.Form!NameOfSubformControl <> "" Then

Cancel = True
Me![SomeControl].SetFocus

End If

End Sub

HTH

--
_________

Sean Bailey


:

Hello there,

I would like to add an statement to the close button on a main form that
prevents the main form from closing if there are values in the NAME field of
a subform. The subform is a datasheet form, so I can see several lines of
data. The idea is that the user would only be able to close the main form if
there are no values at all in the NAME field of the subform. Ideas?

Thanks!

alepag
 
G

Guest

Hi again,

I'm still getting error messages. This one's different, though: "Microsoft
Office Access can't find the field 'PATIENT_NAME' referred to in your
expression". I double checked the names and everything seems to be fine. The
only thing is that the field in the subform is called "PATIENT NAME" and not
"PATIENT_NAME" as I entered it in the code, but that should not be a problem.

Thanks for your help, and your patience

Beetle said:
Try using the following method to refer to the subform in your code;

(Me!sfrm_Pts_Queue_Or_InProcess.Form!PATIENT_NAME)

So it's Name of the main form (Me), Name of the subform control, then the
name of the control within the subform. Notice the extra .Form after the
subform name but before the control name. It won't work without this.

HTH
--
_________

Sean Bailey


Alejandro said:
I forgot to tell you: when I try to use the close button, I get the following
message:

"Microsfot Office Access can't find the form "sfrm_Pts_Queue_Or_InProcess"
referred to in a macro expression or Visual Basic code".

It seems that Access can't find the subform within the main form...I can't
figure out what's wrong here.

Thanks again!


Alejandro said:
Hello Beetle,

Thanks for the advice. However, that's pretty much what I did, and it didn't
work. Here's my code:

If Not IsNull(Forms!sfrm_Pts_Queue_Or_InProcess!PATIENT_NAME) Then
MsgBox "There are patients still being admitted"
DoCmd.CancelEvent
Else
DoCmd.Close
End If

Do you see anything wrong with that code?

Thanks!

:

You could use the forms Unload event to trap for this. The code might look
something like;

Private Sub Form_Unload(Cancel As Integer)

If Not IsNull (Me!NameOfSubform.Form!NameOfSubformControl) Then

Cancel = True
Me![SomeControl].SetFocus

End If

End Sub

If you want to allow a zero length string in the field then you would modify
it like;

If Not IsNull (Me!NameOfSubform.Form!NameOfSubformControl) OR _
Me!NameOfSubform.Form!NameOfSubformControl <> "" Then

Cancel = True
Me![SomeControl].SetFocus

End If

End Sub

HTH

--
_________

Sean Bailey


:

Hello there,

I would like to add an statement to the close button on a main form that
prevents the main form from closing if there are values in the NAME field of
a subform. The subform is a datasheet form, so I can see several lines of
data. The idea is that the user would only be able to close the main form if
there are no values at all in the NAME field of the subform. Ideas?

Thanks!

alepag
 
P

Pieter Wijnen

And why should PATIENT NAME be the Same as PATIENT_NAME?
You should not rely on the feature that Access (in code) will accept _ for
space.
In fact you should never use spaces etc in Field / or Control names, the
Caption property is for that purpose.
You do in this case obviously need to use [PATIENT NAME]

Pieter

Alejandro said:
Hi again,

I'm still getting error messages. This one's different, though: "Microsoft
Office Access can't find the field 'PATIENT_NAME' referred to in your
expression". I double checked the names and everything seems to be fine.
The
only thing is that the field in the subform is called "PATIENT NAME" and
not
"PATIENT_NAME" as I entered it in the code, but that should not be a
problem.

Thanks for your help, and your patience

Beetle said:
Try using the following method to refer to the subform in your code;

(Me!sfrm_Pts_Queue_Or_InProcess.Form!PATIENT_NAME)

So it's Name of the main form (Me), Name of the subform control, then the
name of the control within the subform. Notice the extra .Form after the
subform name but before the control name. It won't work without this.

HTH
--
_________

Sean Bailey


Alejandro said:
I forgot to tell you: when I try to use the close button, I get the
following
message:

"Microsfot Office Access can't find the form
"sfrm_Pts_Queue_Or_InProcess"
referred to in a macro expression or Visual Basic code".

It seems that Access can't find the subform within the main form...I
can't
figure out what's wrong here.

Thanks again!


:

Hello Beetle,

Thanks for the advice. However, that's pretty much what I did, and it
didn't
work. Here's my code:

If Not IsNull(Forms!sfrm_Pts_Queue_Or_InProcess!PATIENT_NAME) Then
MsgBox "There are patients still being admitted"
DoCmd.CancelEvent
Else
DoCmd.Close
End If

Do you see anything wrong with that code?

Thanks!

:

You could use the forms Unload event to trap for this. The code
might look
something like;

Private Sub Form_Unload(Cancel As Integer)

If Not IsNull (Me!NameOfSubform.Form!NameOfSubformControl) Then

Cancel = True
Me![SomeControl].SetFocus

End If

End Sub

If you want to allow a zero length string in the field then you
would modify
it like;

If Not IsNull (Me!NameOfSubform.Form!NameOfSubformControl) OR _
Me!NameOfSubform.Form!NameOfSubformControl <> "" Then

Cancel = True
Me![SomeControl].SetFocus

End If

End Sub

HTH

--
_________

Sean Bailey


:

Hello there,

I would like to add an statement to the close button on a main
form that
prevents the main form from closing if there are values in the
NAME field of
a subform. The subform is a datasheet form, so I can see several
lines of
data. The idea is that the user would only be able to close the
main form if
there are no values at all in the NAME field of the subform.
Ideas?

Thanks!

alepag
 
G

Guest

Hi Pieter,

I had tried that as well (using brackets) but all I got was a different
error message. For this case I get "This actions requires an Object Name
argument". Here's the code I'm using; hopefully you'll be able to tell me
what's wrong with it.

If Not IsNull(Me!sfrm_Pts_Queue_Or_InProcess.Form![PATIENT NAME]) Then
MsgBox "There are patients still being admitted"
DoCmd.CancelEvent
Else
DoCmd.Close acForm, frm_Pt_Info_FrontDesk
End If

Thanks!

Pieter Wijnen said:
And why should PATIENT NAME be the Same as PATIENT_NAME?
You should not rely on the feature that Access (in code) will accept _ for
space.
In fact you should never use spaces etc in Field / or Control names, the
Caption property is for that purpose.
You do in this case obviously need to use [PATIENT NAME]

Pieter

Alejandro said:
Hi again,

I'm still getting error messages. This one's different, though: "Microsoft
Office Access can't find the field 'PATIENT_NAME' referred to in your
expression". I double checked the names and everything seems to be fine.
The
only thing is that the field in the subform is called "PATIENT NAME" and
not
"PATIENT_NAME" as I entered it in the code, but that should not be a
problem.

Thanks for your help, and your patience

Beetle said:
Try using the following method to refer to the subform in your code;

(Me!sfrm_Pts_Queue_Or_InProcess.Form!PATIENT_NAME)

So it's Name of the main form (Me), Name of the subform control, then the
name of the control within the subform. Notice the extra .Form after the
subform name but before the control name. It won't work without this.

HTH
--
_________

Sean Bailey


:

I forgot to tell you: when I try to use the close button, I get the
following
message:

"Microsfot Office Access can't find the form
"sfrm_Pts_Queue_Or_InProcess"
referred to in a macro expression or Visual Basic code".

It seems that Access can't find the subform within the main form...I
can't
figure out what's wrong here.

Thanks again!


:

Hello Beetle,

Thanks for the advice. However, that's pretty much what I did, and it
didn't
work. Here's my code:

If Not IsNull(Forms!sfrm_Pts_Queue_Or_InProcess!PATIENT_NAME) Then
MsgBox "There are patients still being admitted"
DoCmd.CancelEvent
Else
DoCmd.Close
End If

Do you see anything wrong with that code?

Thanks!

:

You could use the forms Unload event to trap for this. The code
might look
something like;

Private Sub Form_Unload(Cancel As Integer)

If Not IsNull (Me!NameOfSubform.Form!NameOfSubformControl) Then

Cancel = True
Me![SomeControl].SetFocus

End If

End Sub

If you want to allow a zero length string in the field then you
would modify
it like;

If Not IsNull (Me!NameOfSubform.Form!NameOfSubformControl) OR _
Me!NameOfSubform.Form!NameOfSubformControl <> "" Then

Cancel = True
Me![SomeControl].SetFocus

End If

End Sub

HTH

--
_________

Sean Bailey


:

Hello there,

I would like to add an statement to the close button on a main
form that
prevents the main form from closing if there are values in the
NAME field of
a subform. The subform is a datasheet form, so I can see several
lines of
data. The idea is that the user would only be able to close the
main form if
there are no values at all in the NAME field of the subform.
Ideas?

Thanks!

alepag
 
P

Pieter Wijnen

on what line does it bomb out?

Pieter

Alejandro said:
Hi Pieter,

I had tried that as well (using brackets) but all I got was a different
error message. For this case I get "This actions requires an Object Name
argument". Here's the code I'm using; hopefully you'll be able to tell me
what's wrong with it.

If Not IsNull(Me!sfrm_Pts_Queue_Or_InProcess.Form![PATIENT NAME]) Then
MsgBox "There are patients still being admitted"
DoCmd.CancelEvent
Else
DoCmd.Close acForm, frm_Pt_Info_FrontDesk
End If

Thanks!

Pieter Wijnen said:
And why should PATIENT NAME be the Same as PATIENT_NAME?
You should not rely on the feature that Access (in code) will accept _
for
space.
In fact you should never use spaces etc in Field / or Control names, the
Caption property is for that purpose.
You do in this case obviously need to use [PATIENT NAME]

Pieter

Alejandro said:
Hi again,

I'm still getting error messages. This one's different, though:
"Microsoft
Office Access can't find the field 'PATIENT_NAME' referred to in your
expression". I double checked the names and everything seems to be
fine.
The
only thing is that the field in the subform is called "PATIENT NAME"
and
not
"PATIENT_NAME" as I entered it in the code, but that should not be a
problem.

Thanks for your help, and your patience

:

Try using the following method to refer to the subform in your code;

(Me!sfrm_Pts_Queue_Or_InProcess.Form!PATIENT_NAME)

So it's Name of the main form (Me), Name of the subform control, then
the
name of the control within the subform. Notice the extra .Form after
the
subform name but before the control name. It won't work without this.

HTH
--
_________

Sean Bailey


:

I forgot to tell you: when I try to use the close button, I get the
following
message:

"Microsfot Office Access can't find the form
"sfrm_Pts_Queue_Or_InProcess"
referred to in a macro expression or Visual Basic code".

It seems that Access can't find the subform within the main form...I
can't
figure out what's wrong here.

Thanks again!


:

Hello Beetle,

Thanks for the advice. However, that's pretty much what I did, and
it
didn't
work. Here's my code:

If Not IsNull(Forms!sfrm_Pts_Queue_Or_InProcess!PATIENT_NAME) Then
MsgBox "There are patients still being admitted"
DoCmd.CancelEvent
Else
DoCmd.Close
End If

Do you see anything wrong with that code?

Thanks!

:

You could use the forms Unload event to trap for this. The code
might look
something like;

Private Sub Form_Unload(Cancel As Integer)

If Not IsNull (Me!NameOfSubform.Form!NameOfSubformControl) Then

Cancel = True
Me![SomeControl].SetFocus

End If

End Sub

If you want to allow a zero length string in the field then you
would modify
it like;

If Not IsNull (Me!NameOfSubform.Form!NameOfSubformControl) OR _
Me!NameOfSubform.Form!NameOfSubformControl <> "" Then

Cancel = True
Me![SomeControl].SetFocus

End If

End Sub

HTH

--
_________

Sean Bailey


:

Hello there,

I would like to add an statement to the close button on a main
form that
prevents the main form from closing if there are values in the
NAME field of
a subform. The subform is a datasheet form, so I can see
several
lines of
data. The idea is that the user would only be able to close
the
main form if
there are no values at all in the NAME field of the subform.
Ideas?

Thanks!

alepag
 
P

Pieter Wijnen

and also replace the ! with .

Pieter
Alejandro said:
Hi Pieter,

I had tried that as well (using brackets) but all I got was a different
error message. For this case I get "This actions requires an Object Name
argument". Here's the code I'm using; hopefully you'll be able to tell me
what's wrong with it.

If Not IsNull(Me!sfrm_Pts_Queue_Or_InProcess.Form![PATIENT NAME]) Then
MsgBox "There are patients still being admitted"
DoCmd.CancelEvent
Else
DoCmd.Close acForm, frm_Pt_Info_FrontDesk
End If

Thanks!

Pieter Wijnen said:
And why should PATIENT NAME be the Same as PATIENT_NAME?
You should not rely on the feature that Access (in code) will accept _
for
space.
In fact you should never use spaces etc in Field / or Control names, the
Caption property is for that purpose.
You do in this case obviously need to use [PATIENT NAME]

Pieter

Alejandro said:
Hi again,

I'm still getting error messages. This one's different, though:
"Microsoft
Office Access can't find the field 'PATIENT_NAME' referred to in your
expression". I double checked the names and everything seems to be
fine.
The
only thing is that the field in the subform is called "PATIENT NAME"
and
not
"PATIENT_NAME" as I entered it in the code, but that should not be a
problem.

Thanks for your help, and your patience

:

Try using the following method to refer to the subform in your code;

(Me!sfrm_Pts_Queue_Or_InProcess.Form!PATIENT_NAME)

So it's Name of the main form (Me), Name of the subform control, then
the
name of the control within the subform. Notice the extra .Form after
the
subform name but before the control name. It won't work without this.

HTH
--
_________

Sean Bailey


:

I forgot to tell you: when I try to use the close button, I get the
following
message:

"Microsfot Office Access can't find the form
"sfrm_Pts_Queue_Or_InProcess"
referred to in a macro expression or Visual Basic code".

It seems that Access can't find the subform within the main form...I
can't
figure out what's wrong here.

Thanks again!


:

Hello Beetle,

Thanks for the advice. However, that's pretty much what I did, and
it
didn't
work. Here's my code:

If Not IsNull(Forms!sfrm_Pts_Queue_Or_InProcess!PATIENT_NAME) Then
MsgBox "There are patients still being admitted"
DoCmd.CancelEvent
Else
DoCmd.Close
End If

Do you see anything wrong with that code?

Thanks!

:

You could use the forms Unload event to trap for this. The code
might look
something like;

Private Sub Form_Unload(Cancel As Integer)

If Not IsNull (Me!NameOfSubform.Form!NameOfSubformControl) Then

Cancel = True
Me![SomeControl].SetFocus

End If

End Sub

If you want to allow a zero length string in the field then you
would modify
it like;

If Not IsNull (Me!NameOfSubform.Form!NameOfSubformControl) OR _
Me!NameOfSubform.Form!NameOfSubformControl <> "" Then

Cancel = True
Me![SomeControl].SetFocus

End If

End Sub

HTH

--
_________

Sean Bailey


:

Hello there,

I would like to add an statement to the close button on a main
form that
prevents the main form from closing if there are values in the
NAME field of
a subform. The subform is a datasheet form, so I can see
several
lines of
data. The idea is that the user would only be able to close
the
main form if
there are no values at all in the NAME field of the subform.
Ideas?

Thanks!

alepag
 
P

Pieter Wijnen

And if still no luck, try

Dim SFC As Access.Control
Dim SF As Access.Form
dim sfcc as Access.Control

set sfc = me.sfrm_Pts_Queue_Or_InProcess
set sf = c.form
set sfcc =sf.controls("[PATIENT NAME]")

to figure out where your code bug is
hth

Pieter

Alejandro said:
Hi Pieter,

I had tried that as well (using brackets) but all I got was a different
error message. For this case I get "This actions requires an Object Name
argument". Here's the code I'm using; hopefully you'll be able to tell me
what's wrong with it.

If Not IsNull(Me!sfrm_Pts_Queue_Or_InProcess.Form![PATIENT NAME]) Then
MsgBox "There are patients still being admitted"
DoCmd.CancelEvent
Else
DoCmd.Close acForm, frm_Pt_Info_FrontDesk
End If

Thanks!

Pieter Wijnen said:
And why should PATIENT NAME be the Same as PATIENT_NAME?
You should not rely on the feature that Access (in code) will accept _
for
space.
In fact you should never use spaces etc in Field / or Control names, the
Caption property is for that purpose.
You do in this case obviously need to use [PATIENT NAME]

Pieter

Alejandro said:
Hi again,

I'm still getting error messages. This one's different, though:
"Microsoft
Office Access can't find the field 'PATIENT_NAME' referred to in your
expression". I double checked the names and everything seems to be
fine.
The
only thing is that the field in the subform is called "PATIENT NAME"
and
not
"PATIENT_NAME" as I entered it in the code, but that should not be a
problem.

Thanks for your help, and your patience

:

Try using the following method to refer to the subform in your code;

(Me!sfrm_Pts_Queue_Or_InProcess.Form!PATIENT_NAME)

So it's Name of the main form (Me), Name of the subform control, then
the
name of the control within the subform. Notice the extra .Form after
the
subform name but before the control name. It won't work without this.

HTH
--
_________

Sean Bailey


:

I forgot to tell you: when I try to use the close button, I get the
following
message:

"Microsfot Office Access can't find the form
"sfrm_Pts_Queue_Or_InProcess"
referred to in a macro expression or Visual Basic code".

It seems that Access can't find the subform within the main form...I
can't
figure out what's wrong here.

Thanks again!


:

Hello Beetle,

Thanks for the advice. However, that's pretty much what I did, and
it
didn't
work. Here's my code:

If Not IsNull(Forms!sfrm_Pts_Queue_Or_InProcess!PATIENT_NAME) Then
MsgBox "There are patients still being admitted"
DoCmd.CancelEvent
Else
DoCmd.Close
End If

Do you see anything wrong with that code?

Thanks!

:

You could use the forms Unload event to trap for this. The code
might look
something like;

Private Sub Form_Unload(Cancel As Integer)

If Not IsNull (Me!NameOfSubform.Form!NameOfSubformControl) Then

Cancel = True
Me![SomeControl].SetFocus

End If

End Sub

If you want to allow a zero length string in the field then you
would modify
it like;

If Not IsNull (Me!NameOfSubform.Form!NameOfSubformControl) OR _
Me!NameOfSubform.Form!NameOfSubformControl <> "" Then

Cancel = True
Me![SomeControl].SetFocus

End If

End Sub

HTH

--
_________

Sean Bailey


:

Hello there,

I would like to add an statement to the close button on a main
form that
prevents the main form from closing if there are values in the
NAME field of
a subform. The subform is a datasheet form, so I can see
several
lines of
data. The idea is that the user would only be able to close
the
main form if
there are no values at all in the NAME field of the subform.
Ideas?

Thanks!

alepag
 

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