When open form close previous

Haytham

Registered User.
Local time
Today, 16:02
Joined
Jun 27, 2001
Messages
162
Hi All, my question is when I open a form th' a command button from a switchboard, I want to write a code to close the main form, so by closing the form, the first one will not appear. Any help please...
Thanks in advance
 
Not sure of the question here. I'm not clear by your description of the problem, but I'll try.

You need to create a module naming the function something like OpenFirst().

Write your Code to first close the main form and then to open the second.

On the action option of the switchboard choose Run Code and use the function name OpenFirst. NOTE: Do NOT put the () in the name. This drove me crazy for hours until I figured that out.

Anyway, your code will run when that button of the switchboard is hit instead of the second form opening up.

Is that what you are trying to do?
 
Hi jwindon
Thanks to your reply.
Well, sorry I'm not familiar with writing the code in modules.
I tried to create a module named: OpenFirst.
I wrote the code as follows:

dim stDoc As String
dim stdoc1 as string
stdoc = "ContactDetails"
stdoc1 = "MainForm"
Docmd. OpenForm stdoc
docmd.close stdoc1

All the time it gives me error message.
Follow up is highly appreciated.
Thanks a lot.
 
Haythem:

As I said, I wasn't sure of what you are doing.

What is the form that opens when your dbase starts? I was assuming it is a switchboard that you created with Switchboard manager.

But in anycase...To create that module. Goto the Modules Icon on the bar on the left in the database window. Go up to where it says design and new and hit new. When the VB window opens you will see Option Compare Database...

Under that put this Code:

Function OpenFirst()
DoCmd.Close acForm, "Switchboard", acSaveNo
DoCmd.OpenForm "frmName2", acNormal, , , acFormEdit, acWindowNormal

End Function

Now, back in your switchboard, you will goto the item that you use to make this happen. The text could read "Enter Record", your action will be Run Code, Function Name will be OpenFirst

If you are NOT using a switchboard, you can modify the code above to be set on the OnClick event property of a command button and modify the name "Switchboard" to that current form's name.

HTH, If not, I will keep trying.
 
Haytham, here is a suggestion of how to do this on a form even though you are new to Access and code. I am presuming that you wish to have a command button on FORM1 that will open FORM2 and close FORM1. I will address your problem that way, trying to take your claim of inexperience into account.

Try this on a test form so you don't whack your main form. Build a FORM2 to contain something. Anything. Now build FORM1 to contain something different. Make sure your Wizards button appears depressed on your forms toolbar. Create a command button. The wizard will allow you to choose what you want that button to do. You can tell it to open a form and specify FORM2 as that form. The last thing the wizard asks is what you want to call the button. Choose a distinctive name, don't accept the default name. Click FINISH. When you do that, part 1 is done.

Now to part 2. Still in design mode of FORM1, click the CODE icon in the top toolbar. Using the dropdown lists, find the code that underlies the distinctive name you chose in part 1. The editor will find that for you.

Somewhere in that code, you will see a line that looks like

DoCmd.OpenForm FORM2, ...

(where the ... is some parameters.)

After that line, insert code like this:

DoCmd.Close FORM1

This line should occur BEFORE the line that usually gets put in by the wizard that issues a GOTO <exit point>.

From the toolbar, find and use the COMPILE and SAVE icons (in that order). Change from design view to form view and try it out. If you get an error, click the HELP option of the error messagebox to see what it is trying to tell you.

Once you get this working for your test forms, you can go back and implement it for the real thing. In your case, FORM1 will be the switchboard and FORM2 will be your targeted form.



[This message has been edited by The_Doc_Man (edited 09-28-2001).]
 
I have done something similar to this, but what i did was have a hyperlink on the button on form 1 pointing to FORM2, which an OnClick macro that was just a close form action.
Lo-Tech but it works
 

Users who are viewing this thread

Back
Top Bottom