Solved

Set TempVar value based on a combo box?

Posted on 2010-11-29
7
1,971 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
ID: 34232450
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
ID: 34232459
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
ID: 34232820
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
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.

 
LVL 7

Expert Comment

by:RemRemRem
ID: 34232886
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
ID: 34232918
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
ID: 34232950
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
ID: 34233174
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

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 see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
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 …

820 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