Solved

How to use TempVars to open a form?

Posted on 2016-10-18
3
38 Views
Last Modified: 2016-10-19
Dear Experts,

I currently have a button that opens a form using an embedded macro.
screenshotI 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!
0
Comment
Question by:shogun5
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
COACHMAN99 earned 500 total points
ID: 41849315
assuming 'tempvars' is field that is populated prior to opening the form, one could use the parameter in the criteria of the query that the form is built on (recordsource) i.e. 'where field = " & form!whatever.field. Use the crtiteria field in the query designer to identify and select the relevant field.
0
 

Author Comment

by:shogun5
ID: 41850095
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.
0
 

Author Comment

by:shogun5
ID: 41850174
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

0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Modern/Metro styled message box and input box that directly can replace MsgBox() and InputBox()in Microsoft Access 2013 and later. Also included is a preconfigured error box to be used in error handling.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now