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

Run Queries on Close of DB without Form ???!!!

P: 44
Hi,
I want to have some queries run on close of my database like the function "Repair on Close" But I don't want to use a form with VBA code or command buttons doing it. Is there any other possibility ??!!
Thanks in advance for answers :)
Oct 26 '06 #1
Share this Question
Share on Google+
13 Replies


NeoPa
Expert Mod 15k+
P: 31,473
I don't believe there is a way - I've had a look around, but I'll watch this thread with interest in case someone finds a way.
Very interesting question BTW.
Oct 26 '06 #2

Andrew Thackray
P: 76
There is no direct way. However this is a workaround that has the same effect

1 - create a blank form
2 - In its on Unload event run the code you want to execute when the database closes.
3 - set the forms visible properties to False so it is invisible
4 - create an autoexec macro that opens the form invisibly when the database opens.

If you do this closing the database will unload the hidden form and trigger the code you want to execute when the database closes.
Oct 26 '06 #3

P: 44
Hi Andrew,
that's really a good indirect way :) I have just one question. User can close the database pressing the little x-button on the screen. They actually always do it, if the database doesn't have a form exiting the application. Are you sure that hitting this little x will run the unload event in the hidden form? I ask because I tried something like that already and it didn't seem to workmout. But maybe I missed something and made it wrong...?


There is no direct way. However this is a workaround that has the same effect

1 - create a blank form
2 - In its on Unload event run the code you want to execute when the database closes.
3 - set the forms visible properties to False so it is invisible
4 - create an autoexec macro that opens the form invisibly when the database opens.

If you do this closing the database will unload the hidden form and trigger the code you want to execute when the database closes.
Oct 26 '06 #4

P: 44
Forget my last post. IT IS WORKING :) :) :)
The only thing is I can't get the form invisible there is no such a property. I will try with a new form...Maybe that helps!
But thanks for your great help!
Ciao

Hi Andrew,
that's really a good indirect way :) I have just one question. User can close the database pressing the little x-button on the screen. They actually always do it, if the database doesn't have a form exiting the application. Are you sure that hitting this little x will run the unload event in the hidden form? I ask because I tried something like that already and it didn't seem to workmout. But maybe I missed something and made it wrong...?
Oct 26 '06 #5

Andrew Thackray
P: 76
Forget my last post. IT IS WORKING :) :) :)
The only thing is I can't get the form invisible there is no such a property. I will try with a new form...Maybe that helps!
But thanks for your great help!
Ciao
Glad it works.

I forgot, you cant't set a forms visible property but you can use the HIDE method on it.

You can load to form invisibly with the followig code line

Forms("Myform").hide.

This loads the form but makes it not visible to the user
Oct 26 '06 #6

NeoPa
Expert Mod 15k+
P: 31,473
This is a funny one.

You can't set the .Visible property directly - instead you call the .Hide() & .Show() methods of the form.
Expand|Select|Wrap|Line Numbers
  1. Call Form_frmDummy.Hide()
Oct 26 '06 #7

P: 44
I don't have a comand like "hide" in my libraries. Do I need somethig special. My code is now:

Private Sub Form_Load()
Forms("frm_not_close").hide
End Sub

And not working...


Glad it works.

I forgot, you cant't set a forms visible property but you can use the HIDE method on it.

You can load to form invisibly with the followig code line

Forms("Myform").hide.

This loads the form but makes it not visible to the user
Oct 26 '06 #8

P: 44
Can you give me maybe the full code? I'm not really that professional with VBA. Just started...
:)

This is a funny one.

You can't set the .Visible property directly - instead you call the .Hide() & .Show() methods of the form.
Expand|Select|Wrap|Line Numbers
  1. Call Form_frmDummy.Hide()
Oct 27 '06 #9

Andrew Thackray
P: 76
I tried the Hide command on a form but it also didn't work

However putting this line in the forms Open event did work

me.visible = false

It seems that although you can't see the visible property in a forms properties sheet, you can still reference id it VBA.
Oct 27 '06 #10

P: 44
Hm. It's not working. The only code I have in the form is the following:

Private Sub Form_Open(Cancel As Integer)
Me.Visible = False
End Sub

Private Sub Form_Unload(Cancel As Integer)
DoCmd.RunMacro "mcr_001_Run_Make_Table_Queries"
End Sub

Still the form is visible when I open the database. Any suggestion?

I tried the Hide command on a form but it also didn't work

However putting this line in the forms Open event did work

me.visible = false

It seems that although you can't see the visible property in a forms properties sheet, you can still reference id it VBA.
Oct 27 '06 #11

Andrew Thackray
P: 76
I put the me.visible line in the form_load event.

However this is wierd. I tested the code by inserting it in an existing form in design view & then clicking the form view button. Lo & Behold the form dissapears.

However if I call the same form from a swithchboard entry it does not disappear !!

If i step through the code the form duly disappears as the me.visible = false is executed but promptly re-appears when the on load or on open routines terminate. Acces itself must set the visible property to true as part of the load & open events after the code is executed

However I put the line in the Form_Activate event and this seems to work

the code is as follows

Private Sub Form_Activate()

Me.Visible = False

End Sub
Oct 27 '06 #12

PEB
Expert 100+
P: 1,418
PEB
And PLS 1 question?

Do you have a Switchboard in your datbase? Why don't you do it Modal... So when you close the database as you want it will be the last one to close in fact i fyou've setup to not appear the database window of course!

And on form close you can express what to happen! :)
Oct 27 '06 #13

P: 44
Yeah PEB, i wished this would be the situation. Actually I can't persuade the user to have his database running with a nice fancy switchboard. The user is more down-to-earth. So no from no switchboard and the possibility that the user closes the database with the little cross in the upper right side of his screen :)

But I try the me.visible on Activate and if this does not help the user will have a little picture somewhere, which is the form.

Thanks to everybody :) :)

And PLS 1 question?

Do you have a Switchboard in your datbase? Why don't you do it Modal... So when you close the database as you want it will be the last one to close in fact i fyou've setup to not appear the database window of course!

And on form close you can express what to happen! :)
Oct 29 '06 #14

Post your reply

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