473,320 Members | 2,145 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,320 software developers and data experts.

close access application

mseo
181 100+
hi,
can I prevent closing the database if any report or form is opened in the application?
thank you
Jun 11 '10 #1
14 4448
patjones
931 Expert 512MB
You would need to provide a little more logic. Why is the database closing to begin with?

Pat
Jun 11 '10 #2
mseo
181 100+
@zepphead80
hi,
thanks for your quick reply
I need prevent close the whole application from 'X' button if any form or report is opened because I have forms that have Exit buttons and if the user closed the database the data in the forms would be saved if the forms closed in any other way except the Exit button
for instance if I opened form and filled some data and I need to exit without save, if I click Exit the data will not be saved (deleted especially with mainforms and subforms)but if I closed the entire application that would big problem
the second problem what about if I have sudden outage
Jun 11 '10 #3
MMcCarthy
14,534 Expert Mod 8TB
You need to keep a hidden form running in the background of the application while it is running. Then if anyone tries to close out of the application that forms unload event will trigger. You can then add any code you want to that form to be triggered if set criteria aren't satisfied.

However, there is not much you can do about a sudden outage in that it will force a kill of the file rather than a close out.

One thing I could suggest is that if your only concern is that any record save is done through the proper close process then you could add code to the unload event of each form to undo any changes. Any "saved" changes would not be affected.

Something like ...

Expand|Select|Wrap|Line Numbers
  1. If Me.Dirty Then
  2.    Me.Undo
  3. End If
Jun 11 '10 #4
slenish
283 100+
Adding to what msquared said,

if you are wanting to make it so the program wont close when people push the X button up in the top right corner you can disable that button on your forms so users can not click it to close a form. Go to your form properties under the Format tab and look for Close Button and change that to No. Then you can create a command button users have to press in order to close.
Jun 11 '10 #5
NeoPa
32,556 Expert Mod 16PB
That doesn't actually make too much difference Slenish. It's good thinking, but not a correct answer in this case. Whether or not the X is enabled, doesn't effect the database closing. If you already have a form open, then handling the Unload event can, but you can't disable the X button for the application which would be the relevant point here. That is why a form (probably hidden) can help. The X button of the form wouldn't be important though.

** Edit ** (See post #12)
I retract this comment. See more recent posts.
Jun 12 '10 #6
NeoPa
32,556 Expert Mod 16PB
mseo: I need prevent close the whole application from 'X' button if any form or report is opened because I have forms that have Exit buttons and if the user closed the database the data in the forms would be saved if the forms closed in any other way except the Exit button.
This is an indication that your form is not properly and logically coded. If you want code to execute whenever the form is closed, and you also want an Exit button, then put the code in the event that handles the form closing, and in the event for clicking on the button, simply close the form.

** Edit ** (See post #12)
Now I better understand the question I retract this. It is not appropriate for this situation, though it is for most others.
Jun 12 '10 #7
mseo
181 100+
thank you for your replies
here is more details about the problem
I have forms for add orders, invoices, receipts,...etc
those forms have subforms, and as you all know that when I setfocus on the subform after filling the required fields in mainforms the data in mainforms access saves it automatically so if I opened any form and filled some fields ( an ID was generated) and I want to cancel the entire data entry operation Exit button holds the code to do that, so any other way to exit the forms such as closing the application or outage, could be a problem, so I want to make something prevents closing the application if any report or form is opened
in here you provided me with good idea that could be implemented but I am not familiar with this
so if you can provide me with steps
thank you very much
Jun 12 '10 #8
mseo
181 100+
hi, msquared
can you provide me with the steps that help me doing this
thank you very much
Jun 12 '10 #9
gnawoncents
214 100+
so if I opened any form and filled some fields ( an ID was generated) and I want to cancel the entire data entry operation Exit button holds the code to do that, so any other way to exit the forms such as closing the application or outage, could be a problem
mseo,

If all you're really trying to do is ensure the new record is deleted unless the appropriate data is entered (or whatever actions you have tied to the Exit button), it would be simpler to add that coding to the on close event of the main form. That would be a more direct approach than the hidden form.

However, if I am misunderstanding your intent and you truly need to ensure the only way to close the form is through the exit button, it would be a simple matter to do something like the following:

1. Add a hidden yes/no datatype field to the form. We'll call it CloseTest. Set the default value to zero (0).
2. Add a line to your Exit button code that when pressed sets the CloseTest value to Yes (-1).
3. In the form unload event on the form add the following code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Unload(Cancel As Integer)
  2.  
  3. 'Do not close form unless using Exit button
  4. If Me.CloseTest = 0 Then
  5.    'Insert a msgbox with some sort of message here if you want to tell the user why they can't close this way
  6.    Cancel = True
  7. End If
  8.  
  9. End Sub
  10.  
This second method can be a bit draconian and will even make it difficult to edit the code with macros enabled. Consequently, think about exactly what it is you want done, and select the best method to accomplish only that.

You should be able to infer how to modify the above code should you decide to use the hidden form instead. Just make the If/Then check for different criteria.
Jun 12 '10 #10
NeoPa
32,556 Expert Mod 16PB
Anyone who can use the word infer, and do it correctly without actually meaning imply, must be worth listening to. Having read the rest of it too, I can confirm that.
Jun 12 '10 #11
NeoPa
32,556 Expert Mod 16PB
mseo: Can I prevent closing the database if any report or form is opened in the application?
In direct answer to the original question - Yes.

There is no way I know of to determine what, exactly, has triggered the request for a form or report object to be closed. This is why a Command Button control should be used, in this case, to indicate that the operator has requested the form be closed explicitly (See the details in gnawoncents post #10). As Reports don't have this facility, you can insist that all reports are opened only from the forms, and then handle it in all your forms.

NB. I should apologise to Slenish as my replies in posts #6 and #7 are not correct for this situation. I was labouring under a misapprehension at the time.
Jun 12 '10 #12
patjones
931 Expert 512MB
I apologize for jumping in at such a late point. I would like to see if yet another approach is possible.

The way I'm reading this, the central issue really has to do with giving the user total control over whether or not, and when, the information currently shown in the form actually gets committed.

Could this be accomplished using an unbound form? Then the only way changes to the record get saved is if the user hits a button that runs some code to make the changes to the table(s). Otherwise it won't matter if the form closes or the application quits unexpectedly or whatever.

Pat
Jun 14 '10 #13
mseo
181 100+
Could this be accomplished using an unbound form? Then the only way changes to the record get saved is if the user hits a button that runs some code to make the changes to the table(s). Otherwise it won't matter if the form closes or the application quits unexpectedly or whatever
that's completely true
and I did so in my form but I didn't use unbound form
I used bound form with temporary table the problem has been solved
but I still need to know the steps that enable me to prevent closing the application from 'X' button from the application not the form
thank you very much
Jun 14 '10 #14
NeoPa
32,556 Expert Mod 16PB
It seems to me the answer has been posted quite fully (probably in more than one version). If there is something you're not clear about I suggest you explain what that is and we can attempt to clarify.
Jun 14 '10 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: ari | last post by:
Hey all, I was just wondering if there is a way for me to open my access application in a vb.net application and when that access application is open, to close my vb.net application? thanks in...
0
by: lauren quantrell | last post by:
In Access, is there a simple way to determine if another Access application is running and then force it to quit? Example App1 is running. It checks to see if App2 is running. If App2 is...
8
by: John Baker | last post by:
Hi: I have a situation where I need to programmatically open an Access application from an Access applications on the same system. Eventually the second application will close and return control...
5
by: Edward W. | last post by:
I was looking at the data access application block version 2 and considering what I had read about connection pooling in that to use connection pooling successfully, you should close your...
4
by: ad | last post by:
I want to develop DataBase application. How about Data Access Application Block? Is it useful?
4
by: Alpha | last post by:
I have a window Application. this.close(); doesn't stop and close my application when I get an error. Instead it continues trying to execute the following codes. What code do I need to the...
0
by: Matex | last post by:
Hi !!! I have an asp.net application in VB.NET, and need to display msaccess reports on the web. everything looks great but in one step i`m connecting msaccess, retrieving report list and...
3
by: Rob Hughes | last post by:
(This is a crosspost from .data for greater exposure) I am writing an external app that utilizes. The app needs to be able to run repeatedly, but I am having a problem because Access will not...
9
by: dennist685 | last post by:
I created a web project named 'Access' in C:\Inetpub\wwwroot\Access and dropped an .mdb there. I dragged a DetailView to the form, configured it to show two fields of a table, and got...
3
by: lesperancer | last post by:
I've got application A, with a hidden form, whose unload event is cancelled unless you use an 'exit' button (so I can do special processing) this works fine when using just application A and it...
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
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...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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: 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.