Solved

How to use TempVars to open a form?

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
IIF help, YN field 7 22
need to fire confirm() popup window in IE using VBA 2 19
MS Access Delete All Excel sheets 1 10
How best to represent data in Excel? 13 28
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

803 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