Open one, close original then close and open again (1 Viewer)

Tanya

Access Novice
Local time
Today, 10:57
Joined
Sep 7, 2008
Messages
165
I have the following code on frmClasses which closes this form and opens frmCompetencies, so far, everything works fine...

Private Sub CmdCompetencies_Click()
On Error GoTo Err_CmdCompetencies_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmCompetencies"
stLinkCriteria = "[ClassID]=" & Me![ClassID]
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_CmdCompetencies_Click:
Exit Sub
Err_CmdCompetencies_Click:
MsgBox Err.Description
Resume Exit_CmdCompetencies_Click

End Sub

However...

I want to be able to then close frmCompetencies and open frmClasses based on the same classID. So I tried the same approach to opening frmCompetencies but it doesn't open on the classID instead it opens as if I was adding a new class.

Private Sub CmdReturnToClass_Click()
On Error GoTo Err_CmdReturnToClass_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmClasses"
stLinkCriteria = "[ClassID]=" & Me![ClassID]
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_CmdReturnToClass_Click:
Exit Sub
Err_CmdReturnToClass_Click:
MsgBox Err.Description
Resume Exit_CmdReturnToClass_Click

I would appreciate it if someone could suggest how I may be able to accomplish this task. The reason I want to close the forms is to speed up requeries.

cheers
Tanya
 

rat_b76

Registered User.
Local time
Tomorrow, 03:57
Joined
May 20, 2003
Messages
37
Perhaps storing the ClassID in a Global Variable may help, this way you wouldn't be relying on an open form to obtain the ClassID?
 

Tanya

Access Novice
Local time
Today, 10:57
Joined
Sep 7, 2008
Messages
165
what do you mean by global variable?
 

rat_b76

Registered User.
Local time
Tomorrow, 03:57
Joined
May 20, 2003
Messages
37
If you do a search on "global variables" it will come up with many results in regards to what you are after.
 

Users who are viewing this thread

Top Bottom