By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,200 Members | 1,568 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,200 IT Pros & Developers. It's quick & easy.

Controlled Close with the "x" button and subform - is it hopeless?

P: n/a
I've been beating my head against this problem for the last several
days, and I haven't found a decent solution yet. So I'm turning to the
group for some moral support or better yet some answers.

Background:
I want the user to be able to close the form by using the "x" button
in the window title bar, I do not want to disable this. I have found a
nice solution in the Access Developer's Handbook that disables the
"x", however I am hoping to avoid using this solution since I like
having the "x" available to the user.

The form that needs the Controlled Close has a subform in datasheet
view; the subform is linked to the main form using the primary /
foreign key.

My question:
Under this scenario, has anybody made the controlled close to work? If
so, what is the general coding strategy?

I've gone through several iterations of code, here is a mock up of
where I've ended; btw it doesn't work very well, several errors result
in akward form handling.

Form_Load
'Nothing here related to controlled close

Form_Current
'Nothing here either

Form_BeforeUpdate
'Check for empty form
'If empty, exit sub
'Validate form
'If invalid Cancel = True, Exit Sub

Form_Unload
'Call Form_BeforeUpdate
'If invalid form then Cancel = True
'Repopulate form with user input
'Exit Sub

Function ValidateForm
'Check for empty form
'Various error checking
'Check for empty subform (note: user cannot access subform until all
required fields in
'parent form are completed
'Various error checking
'If invalid, returns False and sets mod variable strError to text
describing error

Form_Error
'If incomplete form error (2169) then
'Msgbox allow user to Save ('yes'), Not Save ('no'), or Cancel close
('cancel')
'If user wants to continue editing current record, then
'Prompt user with error msg from mod variable strError
'And set variables up to repopulate form with user input in Form_Unload
Jun 27 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Kelii,

Just a passing thought, but perhaps the answer is to make the form
'borderless' (thin) and maybe modal. Then inside your form you add
your own [x] and title bar etc so that it 'looks' like the form you
desire. The difference here would be that the [x] is actually a
command button that you can assign code to.

The Frog
Jun 27 '08 #2

P: n/a
Frog,

Thanks for the suggestion. I just can't bring myself to do as you
suggest to the form. Not to be offensive, but it seems worse than
disabling the 'x' altogether. I keep thinking that all the other
commercial apps can do it, so why can't I?

Anyhow, I stumbled on a decent work around. I'd love to give the guy /
gal credit, but I can't seem to find the link again. Anyway here goes:

Main form
Declarations area:
'Setup a series of variables that can store the user's input (e.g.,
strDescription, sglQuantitiy)
'Setup variable indicating close is ok (e.g., strOkToClose,
blnOkToClose)

Form_BeforeUpdate
'Check for emtpy form, if so exit
'Validate form, if invalid Cancel = True, exit (this generates your
Form_Error)

Form_Unload
'Check if ok to close
'If not ok to close then restore input using variables from
declarations area
'Empty variables

Form_Error
'In addition to others, select case for DataErr 2169
'Prompt user for option to exit without save or cancel exit
'If exit without save, do so
'If exit with save, set variable to users input for restore in
Form_Unload

Subform:
Form_BeforeUpdate
'Various bits of code to validate input

That's it! Pretty simple. The only drawback is that in my design, you
get two prompts when you attempt to close using the 'x' and the data
in the form or subform is not valid. First you get the error prompt
from the Form_BeforeUpdate, then you get another prompt that asks if
you want to continue. In a perfect world, one could condense this into
one prompt; however I have not been able to do so.

Kelii
Jun 27 '08 #3

P: n/a
On Jun 2, 10:22*am, Kelii <kel...@yahoo.comwrote:
I've been beating my head against this problem for the last several
days, and I haven't found a decent solution yet. So I'm turning to the
group for some moral support or better yet some answers.

Background:
I want the user to be able to close the form by using the "x" button
in the window title bar, I do not want to disable this. I have found a
nice solution in the Access Developer's Handbook that disables the
"x", however I am hoping to avoid using this solution since I like
having the "x" available to the user.

The form that needs the Controlled Close has a subform in datasheet
view; the subform is linked to the main form using the primary /
foreign key.

My question:
Under this scenario, has anybody made the controlled close to work? If
so, what is the general coding strategy?

I've gone through several iterations of code, here is a mock up of
where I've ended; btw it doesn't work very well, several errors result
in akward form handling.

Form_Load
'Nothing here related to controlled close

Form_Current
'Nothing here either

Form_BeforeUpdate
'Check for empty form
'If empty, exit sub
'Validate form
'If invalid Cancel = True, Exit Sub

Form_Unload
'Call Form_BeforeUpdate
'If invalid form then Cancel = True
'Repopulate form with user input
'Exit Sub

Function ValidateForm
'Check for empty form
'Various error checking
'Check for empty subform (note: user cannot access subform until all
required fields in
'parent form are completed
'Various error checking
'If invalid, returns False and sets mod variable strError to text
describing error

Form_Error
'If incomplete form error (2169) then
'Msgbox allow user to Save ('yes'), Not Save ('no'), or Cancel close
('cancel')
'If user wants to continue editing current record, then
'Prompt user with error msg from mod variable strError
'And set variables up to repopulate form with user input in Form_Unload
not sure what you mean by 'controlled close'
you have form A containing a subform B
and the user clicks 'x'
if subform B is dirty, what should happen ?
if form A is dirty, what should happen ?
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.