Solved

Set TempVar value based on a combo box?

Posted on 2010-11-29
7
1,880 Views
Last Modified: 2013-11-27

I need the following sequence to happen:

1. User selects a YEAR from a combo box [cmbo_Year]
2. They open another form (original form closes) and do some stuff
3. They return to the original screen in step 1.
4. I want [cmbo_Year] to show the value that they had selected previously in step 1.

I can't quite seem to figure out how TempVars work (I'm assuming that they are the solution to this problem).

This database is independent, and is NOT used by multiple users.  It is specific for ONE user at a time, so there will be no issues with someone being in there at the same time, and changing the Year combo box value.
Thanks for any help.
0
Comment
Question by:SheaJeff
  • 3
  • 3
7 Comments
 
LVL 2

Assisted Solution

by:compTrack
compTrack earned 200 total points
Comment Utility
Hello There !!

What you need to do is store the value selected in step 1 in a global variable. Let the user do whatever he/she wants to do in step 2.

In step 3 when they return to the original form, you need to obtain the value back from the global variable and display it in whatever way it is that you want.

Alternatively, you can try and store the selected year in Step 1 in a table. And when the user returns back to the form (in step 3) retrieve that value back from the table and display it.

Best Of Luck

compTrack
0
 
LVL 7

Accepted Solution

by:
RemRemRem earned 300 total points
Comment Utility
One of the quickest "cheats" to handle this is to simply make the original form invisible, instead of closing it. Then the value hasn't been wiped when the recordset closes because, well, it never does!

Otherwise, you need to create a global variable (Public gintYear as integer, say) and store the cmbo_Year value in that global variable as you close the form (On Close, gintYear = me.cmbo_Year) until you re-open the form, and then, upon opening it, set the cmbo_Year = gintYear

-Rachel
0
 

Author Comment

by:SheaJeff
Comment Utility
I'm going to accept both of your solutions for the global variable, but have another add-on to this question:

How can I get the [cmbo_Year] default value set back to "current year" when the database is closed?
That way it the form always originally comes up showing the current year.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 7

Expert Comment

by:RemRemRem
Comment Utility
I think what you're actually asking is how do you default it upon opening, in which case you can set the combo box's default value to:

 =year(date())

-Rachel
0
 

Author Comment

by:SheaJeff
Comment Utility
I already have the =year(date()) as the default value.
But once the global variable is set, it seems to over ride the default value...
0
 
LVL 7

Assisted Solution

by:RemRemRem
RemRemRem earned 300 total points
Comment Utility
If this is happening after you've closed and reopened the database, then you've got some code assigning values to the global variable in the wrong place - it may be that you're setting the global variable too soon?

-Rachel
0
 

Author Comment

by:SheaJeff
Comment Utility
I found the problem;
I was setting the value of cmbo_Year on the Form_Open event.  
When the database started up, it would give me a zero until I selected something, then everything worked fine.
I had to add this to the Form_Open assignment for the cmbo_Year:

If gintYear <> 0 then
   cmbo_Year.value = gintYear
Endif
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
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…

728 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

10 Experts available now in Live!

Get 1:1 Help Now