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!

Closing a form while opening another 1

Status
Not open for further replies.

Angel79

Instructor
Dec 18, 2003
20
CA
Hi,
I have a database created and I have everything linked together pretty much like a webpage where the user can click a button to browse through all the pages. But I'm having trouble because every time you click to open another page the old ones stay open and you eventually end up with like 20 pages open at a time. So if anyone has any info on how to close the form you are clicking from while opening the form the link leads to please let me know.

Thanks,
Christa
 
DoCmd.OpenForm "form name to open"
DoCmd.Close acForm, "form name to close"

these two lines of code....together will open the new form and close the other.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
Perhaps, when you call the second form you could include int the OpenForm command the openArgs value of Name() which will send the name of the current form to the new form and then have the OnOpen event of the new form close the old form. But then again, perhaps not. I have only used this to open a form during the OnOpen event of a report. Try it, it might work.
 
You can run code in Form1 that says:

Docmd.close acForm, Me.Name
Docmd.Openform "FormNumber2"


with no problems. Closing the form does *NOT* halt any code running (such as the subroutine you're in currently).

Be careful though, when you need to pass information from form1 to form2, store it in temp variables:



Dim strSSN as string

strSSN = Nz(Me!txtSSN.Value)

Docmd.close acForm, Me.Name
Docmd.Openform "FormNumber2", OpenArgs:=strSSN



I have done this myself many times without problems.
 
Thanks for the quick reply...that worked perfectly. THANKS TONS!!! I've been ripping my hair out over that for the last two days. LOL

I was forgetting the acForm, part and the " " around the form name. Funny how you sometimes forget the simple things.

Thanks again,
Christa
 
Angel79,

You really should let which person know they were the most successful...

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
You're correct mstrmage1768. I read your response and went ahead and tried it and clicked reply once it worked and didn't even see that others have also responded until after I had my reply sent. But thanks to everyone for their response also.

Again, thank you Robert (mstrmage1768).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top