?
Solved

Set TempVar value based on a combo box?

Posted on 2010-11-29
7
Medium Priority
?
2,060 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 2

Assisted Solution

by:compTrack
compTrack earned 800 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 1200 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 1200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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.
Suggested Courses

765 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