Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close form in OnShow event?

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
I have a form that in the OnShow event I'm running a query. If there are no results from that query I don't want to show the form, I want to give the user a message that no records were found and skip the rest of the OnShow event and close the form before it opens.

Is this possible? Is there another way to accomplish what I'm trying to do?

Thanks!
Leslie
 

If the query runs quickly (1 or 2 seconds), I would run it before creating/showing the form. That way if there are results I can .Show the form and if not I can display a message box.

If the query takes more than a couple of seconds to run, I don't like to have my users staring at a dead screen. So I would display a form but not run the query on OnShow (because the form isn't visible yet). I would use one of a couple of techniques(*) to complete the display of the form and have it show a "Running, please wait..." line of static text. And then change the display as appropriate.

(*) My favorite is to post a message during OnCreate and then put my code in the handler for that message. Another way is to use a Timer and put my code in the OnTimer event. The effect is the same.

 
I ended up doing the first thing you suggested. I run the query first and then decide if I should open the form. it doesn't take long and it works fine.

thanks!
leslie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top