Link to home
Start Free TrialLog in
Avatar of Mike Rudolph
Mike RudolphFlag for United States of America

asked on

How to use TempVars to open a form?

Dear Experts,

I currently have a button that opens a form using an embedded macro.
User generated imageI have two forms nearly identical one called frmStudent and frmStudentShort. The 'short' version is a continuous form that displays less information that the original 'frmStudent' form. Anyway, I have several buttons on the frmStudent form that open various popup forms. When the associated popup forms close I either requery the frmStudent or open the frmStudent form again. The problem I am having is now that I have 'copied' the frmStudentShort form all the associated popup forms either requery or open frmStudent which causes an error 'cause the frmStudentShort form is open and not the frmStudent.

That said, I would like to use tempVars and pass the form name in the macro so when I close the associate popup form I can use the tempVars in the command.

Private Sub cmdClose_Click()
      DoCmd.Close acForm, "frmAssignGroups"
      Forms!frmStudent.Requery
End Sub

Open in new window


Instead something like:
Private Sub cmdClose_Click()
      DoCmd.Close acForm, "frmAssignGroups"
     ' Forms!frmStudent.Requery

     Forms! & TempVars!FormName & .Requery
End Sub

Open in new window


Of course the above code does not work so need some help with this.  Alos, how would I open/close a form using TempVars....
 DoCmd.Close acForm, "frmStudent"  ???
 
 DoCmd.OpenForm "frmStudent"  ???

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of COACHMAN99
COACHMAN99

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike Rudolph

ASKER

Actually I don't need to filter the record source I just need to know which form to return to and need to somehow store a variable that allows me to return to either frmStudent or frmStudentShort depending on which form a came from.
All,

So I figured it out. Here is the code when I leave the form:
 Dim ReturnForm As TempVars
  TempVars.Add "ReturnForm", "frmStudentShort"
  

Open in new window


Here is the code when I return to the form:
 DoCmd.OpenForm TempVars!ReturnForm, , , "ClassID = " & Me.ClassID

Open in new window