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

closing form on exit!

Status
Not open for further replies.

dj662003

Technical User
Dec 4, 2003
18
0
0
US
Here it is, I have created a command button (using the wizard) to return me from one form to the main menu (switchboard). The problem is, that when I use this button it does not close the existing form it just tiles it behiind the other one. How can I make it close the existing form and return to the "main menu"?

By the way I do not know code

Thanx In advance
dj66
 
dj66,

With your created button, in the On_click event, put the following code in.

Private Sub cmdExit_Click()

DoCmd.Close acForm, ("frmCurrentForm")
DoCmd.OpenForm ("frmMAINMENU")

End Sub

This should close your current form, and open your switchboard.

Alex
 
When I use that code this is the message that I get

"DEATH PORTAL RECORDS can't find the macro 'Private Sub cmdExit_Click() DoCmd.'

The macro(or it's macro group)doesn't exist, or the macro is new but hasn't been saved.
Note that when you enter the macrogroupname.macroname syntax in an arguement, you must specify the name the macros macro group was last saved under."

What is this telling me? Anyone?
 
dj662003

Use the wizard the create a close button.

Select the command button icon from the toolbox, draw the button where you want it then select Form Operations, and then select Close. The button the wizard makes will close the form properly and return you to the switchboard.

Tel
 
Hi

To avoid mis-spelt form names, the easiest way to close a current form is

Docmd.close acForm, Me.Name

HTH

Alan
 
thanx terry,
but when I just use the close form option with the wizard it just closes the form and returns me to the database window :(
 
dj662003 said:
[blue]when I use this button [purple]it does not close the existing form[/purple] it just tiles it behiind the other one.[/blue]
Either you somehow had another instance of the form your trying to close already open, the wizard came up with faulty code, or [purple]you have something seriously wrong here![/purple]

Post the button code as it is now!

What version Access ya using?

Calvin.gif
See Ya! . . . . . .
 
Hi dj66203

Is it something to do with how the form is opened in the first place? Is the Open operation closing the switchboard as well? - so that when you close the form you only see the Database window?

Also, you could just use a macro, behind the close button, to close the form, since I've always found that it can only close the active form, especially if none is specified.

AS the Aceman says, we could do to see the code.

Tel
 
Well guys here is the code for that button.

Private Sub RETURN_MAIN2_Click()
On Error GoTo Err_RETURN_MAIN2_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "MAIN MENU"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_RETURN_MAIN2_Click:
Exit Sub

Err_RETURN_MAIN2_Click:
MsgBox Err.Description
Resume Exit_RETURN_MAIN2_Click

End Sub


Also I appologize, I am not using a switchboard I am using
Another form with command buttons on it as my main menu.
 
Have you tried any of the above suggestions? For instance using AccessAddict's suggestion within your code?

[tt]Private Sub RETURN_MAIN2_Click()
On Error GoTo Err_RETURN_MAIN2_Click
Dim stDocName As String
stDocName = "MAIN MENU"
Docmd.close acForm, Me.Name
DoCmd.OpenForm stDocName
Exit_RETURN_MAIN2_Click:
Exit Sub
Err_RETURN_MAIN2_Click:
MsgBox Err.Description
Resume Exit_RETURN_MAIN2_Click
End Sub[/tt]

Roy-Vidar
 
Roy, I posted this a couple days ago after I used that code!

"When I use that code this is the message that I get

"DEATH PORTAL RECORDS can't find the macro 'Private Sub cmdExit_Click() DoCmd.'

The macro(or it's macro group)doesn't exist, or the macro is new but hasn't been saved.
Note that when you enter the macrogroupname.macroname syntax in an arguement, you must specify the name the macros macro group was last saved under."

What is this telling me? Anyone?"
 
Yes you posted that, two post's before AccessAddict's suggestion. What that message is probably telling you, is that you've put it in the event property of some control, and not in VBE, therefore it cant find the macro. What we've been trying to suggest from the start, is to use code/VBE (as in the place where you copied what you put a couple of posts above - if that works, then, as suggested several times, adding the docmd.close within should work - tried it?)

Roy-Vidar
 
Yes I did try that code as well and got pretty close to the same error message

"DEATH PORTAL RECORDS can't find the macro 'DoCmd.'

The macro(or it's macro group)doesn't exist, or the macro is new but hasn't been saved.
Note that when you enter the macrogroupname.macroname syntax in an arguement, you must specify the name the macros macro group was last saved under."


 
dj662003 . . . . .

I could be wrong, but there seems to be a communications problem here. [blue]RoyVidar[/blue] has already related to this.

If we say put the code line [blue]DoCmd.Close acForm, "FormName"[/blue] in the click event for the button, tell us exactly how you get it there!

Calvin.gif
See Ya! . . . . . .
 
...and if there are any occurrences of "text" other than [Event Procedure] in the Event properties of controls and forms, remove them (of course if any of those occurrences call macros (shudder;-)) found in the dropdown of the event property, they can stay). Basically that property tells what is supposed to happen when such event happens (someone clicks a button, opening of a form...). The usual stuff called by such event handler, are event procedures in VBE and macros). So - only things "allowed" in that propery, is some macro which is found in the dropdow, or [Event Procedure] which tells Access to execute the procedure assosiated with the event (Private Sub cmdExit_Click()...).

If no such is found, the easisest is probably to recreate the form...

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top