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

Cmd button code for Switchboard

Status
Not open for further replies.

DuncanKing

Programmer
Jan 14, 2004
32
IE
Does anyone know what the code is for a Cmd button on a form that will bring me back to the Switchboard. I've tried "DoCmd.Close" but that brings me back to the access main DB screen (ie tables, wueries, forms reports....)

Thanks


 
The simple enough solution is to use the setfocus method after you close your form. The code for the button should look something like this:

Code:
Private Sub ExitBtn_Click()
  DoCmd.Close
  Forms!Switchboard.SetFocus
End Sub

If the Switchboard form has been minimized, you will also need to either restore it or maximize it. If that is the case, your code will look like this:

Code:
Private Sub ExitBtn_Click()
  DoCmd.Close
  Forms!Switchboard.SetFocus
  DoCmd.Restore
End Sub

The last option is to seperate the SetFocus action from the button and apply it to the on exit event for the form so that any time the form is exited, the user will be returned to the Switchboard. This may be advantagious if you have not disabled the [x] close button, as users may use that instead of your custom button.

-Brian-
I'm not an actor, but I play one on TV.
 
Brian, Thanks for this solution. Here's whats happening now.

Putting the code from either solution, I get the following error when I click on the cmd button "Runtime error 2450" with the message "Microsoft cant find the form switchboad referred to in the macro expression." Do I have to provide a path name. The form is called "Switchboard" and the table is Switchboard_items. All the forms, tables, etc., are in the same file "candidate.mdb." When it offers to debug it highlights " Forms!Switchboard.SetFocus"

Duncan
 
Possibly the switchboard was closed. in which case you could use: DoCmd.OpenForm "Switchboard"

Possibly the switchboard form is named something else. in which case you find out the correct name in your "main db screen"



-Pete
 
Thanks everybody for your help. The form was not open but the DoCmd.OpenForm "Switchboard" fixed that.

Duncan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top