Solved

How to use TempVars to open a form?

Posted on 2016-10-18
3
29 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
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…

747 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

9 Experts available now in Live!

Get 1:1 Help Now