473,324 Members | 2,248 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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

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
3 2196
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Bruce A. Julseth | last post by:
How do I emulate the web page "Close" Button, i. e. the "X" in the upper right hand corner of each web page? Thank you.... Bruce
4
by: moose | last post by:
OK Popup window? No problem PDF in popup? No problem But what about a couple of Close Window buttons? Imagine a "Close Window" button at the top of the popup page. Then the PDF which can...
5
by: Reggie | last post by:
Hi and TIA! I have a form and have set the Close Button to false so that users must exit using my close button. However when I open a Report from this form I want the close button to be available...
4
by: mhifd009 | last post by:
I have disabled a close button in the property section of a form (FRM1), as i open the form the close button has gone (i have programmed close button), but as i close the form, the form that opened...
0
by: bloombloom | last post by:
I am gonna post my AS in hopes that someone can get a good understanding of what i am doing. So here is the code: t1.onRelease = function() { infoField._visible = true; startLoading("cc11.swf");...
3
by: mfleet1973 | last post by:
Hi. Visual Studio 2003. Is there a way to disable another application's form's close button that is on the taskbar? Cheers. Mike.
2
by: Carla Simeoni | last post by:
Assume I have an open Form. Then I click the "normal" window "X" icon (=Close button). How do I assign a function in Form.cs to this event ? In other words if this Form/window is closed I want to...
2
by: Bruce | last post by:
Hello, I have a form in an Access 2003 application which opens maximized. Its CloseButton property is set to false. On this form I have a command button that opens a report in preview mode. ...
0
by: Tony | last post by:
I am continuing to develop an Access 2007 application which was originally converted from Access 2003. In Access 2003 I was able to disable the Access Close button in the top righthand corner of...
5
by: Tony | last post by:
I am continuing to develop an Access 2007 application which was originally converted from Access 2003. In Access 2003 I was able to disable the Access Close button in the top righthand corner of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.