Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to use TempVars to open a form?

Posted on 2016-10-18
3
Medium Priority
?
268 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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
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…

926 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