Close one form and open another

A

Annelie

I used the below listed command button code to close one form and open
another. It works. Then I put the same code in reverse listed below, it
closes the first form but does not open the other one.
Can anyone see why the second one does not work?
Annelie


Private Sub CmdOpenEmplList_Click()
On Error GoTo Err_CmdOpenEmplList_Click

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "FrmEmployeeCurrentData"
DoCmd.Close acForm, "FrmEmployeeCurrentData"

stDocName = "FrmEmployeeList"
DoCmd.OpenForm "FrmEmployeeList", , , stLinkCriteria

Exit_CmdOpenEmplList_Click:
Exit Sub

Err_CmdOpenEmplList_Click:
MsgBox Err.Description
Resume Exit_CmdOpenEmplList_Click

End Sub
----------------------------
Private Sub CmdOpenEmplList_Click()
On Error GoTo Err_CmdOpenEmplList_Click

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "FrmEmployeeList"
DoCmd.Close acForm, "FrmEmployeeList"

stDocName = "FrmEmployeeCurrentData"
DoCmd.OpenForm "FrmEmployeeCurrentData", , , stLinkCriteria

Exit_CmdOpenEmplList_Click:
Exit Sub

Err_CmdOpenEmplList_Click:
MsgBox Err.Description
Resume Exit_CmdOpenEmplList_Click
End Sub
 
E

Eric Butts [MSFT]

Hi Annelie,

I'm not sure where you are using the below code (e.g., in the Form
FrmEmployeeCurrentData)

What I would suggest you do is compare the Form properties of both forms

FrmEmployeeCurrentData - and - FrmEmployeeList

Also compare any VBA code you may have running on the Form.


I hope this helps! If you have additional questions on this topic, please
respond back to this posting.


Regards,

Eric Butts
Microsoft Access Support
(e-mail address removed)
"Microsoft Security Announcement: Have you installed the patch for
Microsoft Security Bulletin MS03-026? If not Microsoft strongly advises
you to review the information at the following link regarding Microsoft
Security Bulletin MS03-026
<http://www.microsoft.com/security/security_bulletins/ms03-026.asp> and/or
to visit Windows Update at <http://windowsupdate.microsoft.com/> to install
the patch. Running the SCAN program from the Windows Update site will help
to insure you are current with all security patches, not just MS03-026."

This posting is provided "AS IS" with no warranties, and confers no rights



--------------------
| From: "Annelie" <[email protected]>
| Subject: Close one form and open another
| Date: Mon, 26 Jul 2004 17:19:16 -0400
| Lines: 47
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.access.formscoding
| NNTP-Posting-Host: adsl-10-103-44.mia.bellsouth.net 65.10.103.44
| Path:
cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13
.phx.gbl
| Xref: cpmsftngxa10.phx.gbl microsoft.public.access.formscoding:240085
| X-Tomcat-NG: microsoft.public.access.formscoding
|
| I used the below listed command button code to close one form and open
| another. It works. Then I put the same code in reverse listed below, it
| closes the first form but does not open the other one.
| Can anyone see why the second one does not work?
| Annelie
|
|
| Private Sub CmdOpenEmplList_Click()
| On Error GoTo Err_CmdOpenEmplList_Click
|
| Dim stDocName As String
| Dim stLinkCriteria As String
| stDocName = "FrmEmployeeCurrentData"
| DoCmd.Close acForm, "FrmEmployeeCurrentData"
|
| stDocName = "FrmEmployeeList"
| DoCmd.OpenForm "FrmEmployeeList", , , stLinkCriteria
|
| Exit_CmdOpenEmplList_Click:
| Exit Sub
|
| Err_CmdOpenEmplList_Click:
| MsgBox Err.Description
| Resume Exit_CmdOpenEmplList_Click
|
| End Sub
| ----------------------------
| Private Sub CmdOpenEmplList_Click()
| On Error GoTo Err_CmdOpenEmplList_Click
|
| Dim stDocName As String
| Dim stLinkCriteria As String
| stDocName = "FrmEmployeeList"
| DoCmd.Close acForm, "FrmEmployeeList"
|
| stDocName = "FrmEmployeeCurrentData"
| DoCmd.OpenForm "FrmEmployeeCurrentData", , , stLinkCriteria
|
| Exit_CmdOpenEmplList_Click:
| Exit Sub
|
| Err_CmdOpenEmplList_Click:
| MsgBox Err.Description
| Resume Exit_CmdOpenEmplList_Click
| End Sub
|
|
|
 
A

Annelie

I checked the code, but there does not seem to be anything that could
prevent the code from opening the form. Although form FrmEmployeeCurrentData
is a much more complication form then FrmEmployeeList. EmployeeList just has
employee information, where FrmEmployeeCurrentData has 2 subforms. The only
thing I can see, which was my problem in the first place is that these two
forms are very much related.
When my user enters payroll data in the form FrmEmployeeCurrentData, and
they find that an employee has been terminated, or got a raise, or is new,
the Form frmEmployeelist has to be opened to make the changes or additions.
I always got errors that the form is in use, or similar to that. So I
figured the easy solution is to create a button that closes one form and
opens the other, and than reverse the situation.
Is there any other way of opening and closing forms? I just starting to
learn VBA.
Annelie
 
P

PC Datasheet

Annelie,

The command button, CmdOpenEmplList, is on the form, FrmEmployeeCurrentData.
When you close this form, you also stop any code below the line closing the form
from executing. The execution of your code stops at DoCmd.Close acForm,
"FrmEmployeeCurrentData". Change your code to open FrmEmployeeList first then
close FrmEmployeeCurrentData and you will be fine!

Steve
PC Datasheet
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top