How to run a query when opening a form?

  • Thread starter Thread starter hkgary33 via AccessMonster.com
  • Start date Start date
H

hkgary33 via AccessMonster.com

Dear all,
I’ve built a form frmMainMenu and a query qryAuto, I would like to ask how to
write an event procedure to automatically run this existing query when
loading this form, but the query result will not be shown, only the number of
records in the query result will be shown in frmMainMenu. (just like when we
log in our email accounts, and it will have a text message showing how many
new emails, how many unread mails…etc)

I wonder if Access has such powerful features to do it, thanks a lot!!!

Gary
 
Hey Gary,

This is totally possible. you can manipulate access to do whatever you
want you just have to be resourceful..use tables as variables and such.
For your need, create an OnOpen event. User the macro designer
because it's easy and it'll get your job done. This is what the macro
should say in this order:

SetWarnings.No
OpenQuery.<QueryName>
Close.Form.frmMainMenu
OpenForm.frmMainMenu

Thats what should run if you're using the form as the primay means to
hold your data. Other wise, if it's in subForm or something, run the
same macro but exclude the Close and Open functions I mentioned. Have
it Requery your listBox, subForm, or whatever you're displaying your
table data in. Simple but it should work..I created a whole user
environment with user limitations, popup windows(even with the access
window shrunk) and a smililar-to-NTFS filesystem idea just with access
limiting/allowing the users ability to write, read, delete, or even
edit. With access, pretty much anything is possible just be creative!

Charlie
 
Sorry Gary,

That first Idea would put you in an endless loop of a closing and
opening form. Better do it this way. Create a form called "Startup".
Then on "Startup" OnOpen, have it run the following:

SetWarnings.No
OpenQuery.<QueryName>
Close.Form.Startup
OpenForm.frmMainMenu

You're set. Now just set "Startup" as the startup form in MSaccess and
everytime you startup, it will run your query, then open your main
menu, thus showing your fresh data. By the way you can do alot with a
startup form like what I just mentioned...even make three or four.
Macros run them so fast you never see them open..you just see the
resluts.
 
Dear all,
I’ve built a form frmMainMenu and a query qryAuto, I would like to ask how to
write an event procedure to automatically run this existing query when
loading this form, but the query result will not be shown, only the number of
records in the query result will be shown in frmMainMenu. (just like when we
log in our email accounts, and it will have a text message showing how many
new emails, how many unread mails…etc)

I wonder if Access has such powerful features to do it, thanks a lot!!!

Gary

No need to actually run or see the query.
In an unbound text control on the frmMainMenu:

=DCount("*","QueryName")
 
Back
Top