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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening several forms on startup, then passing focus to first form 3

Status
Not open for further replies.

cully651

Programmer
Aug 1, 2005
41
US
In Access 2007, I can't find a way to open several forms at startup (creating tabs for each for in a certain order) then passing the focus to the first form (the tab furthest to the left). I can open all the forms and get them in the order I need, but changing focus to the 1st form seems impossible.
 
If something like
Forms("Form1").SetFocus
doesn't do it, then usually you can just send another open command for the form you'd like focused. If the form is already openend then you will set focus to it by goinG

DoCmd.OpenForm "Form1", acNormal

etc
maybe there's a better wAY ...
 
Thanks, but that does't work. Here's why.

Let's say I have 4 forms, named frm1 frm2 etc. In order to get them so that the tabs are in order, I have to specify frm4 as the startup form, and have the following in frm4's load or open event

DoCmd.OpenForm "frm1"
DoCmd.OpenForm "frm2"
DoCmd.OpenForm "frm3"

The form I'm using as the startup form always loads last, because it has to complete the other DoCmd.OpenForm commands before it can finish loading itself. I end up with 4 tabs in the correct order, but the focus is on frm4 instead of frm1 like I have to have it.

My alternative is to build 1 form with a tab control and cram all 4 forms on there as subforms. Not a good way to do it IMO because Access 2007 has tabbed forms already so you get more real estate on the form by using them that way.
 
You could try use the Timer functionality of frm4. Set the timer value to about one second and have the timer event open the other forms and set the frm4 timer to 0.

Duane
Hook'D on Access
MS Access MVP
 
Add a form called "frmOpen". Call this form to open the others, or set it as the default form.
Code:
Private Sub Form_Load()
  Me.Visible = False
  DoCmd.OpenForm "form1"
  DoCmd.OpenForm "form2"
  DoCmd.OpenForm "form3"
  DoCmd.OpenForm "form4"
  DoCmd.OpenForm "form1"
  DoCmd.Close acForm, Me.Name
End Sub
 
Or simply open your startup form frm4 from an AutoExec macro/procedure (and all the other forms for that matter) then each will go through its entire load process and you can still run some code for focus purposes thereafter.

Though using the 'phantom form' suggested by MajP above seems like a simple work-around if you not sure about AutoExec macro.
 
How are ya cully651 . . .

I'm curious as to why loading the forms in reverse order (form4, form3, form2, form1) won't work for you! This would leave the form1 at the top and active.

You could simply set an [blue]AutoExec[/blue] macro to runcode as follows:
Code:
[blue]   DoCmd.OpenForm "form4"
   DoCmd.OpenForm "form3"
   DoCmd.OpenForm "form2"
   DoCmd.OpenForm "form1"[/blue]
... and the forms are in [blue]chronological order[/blue] top to bottom.

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Both the AutoExec macro and the Startup Form work, thanks.

Both the macro and the form need to be handled the same way, by opening the forms in order (left to right) and then opening the first form again like

DoCmd.OpenForm "form1"
DoCmd.OpenForm "form2"
DoCmd.OpenForm "form3"
DoCmd.OpenForm "form4"
DoCmd.OpenForm "form1"

Thanks!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top