Solved

Set default value of Combo box using displayed combo box value

Posted on 2014-01-29
3
746 Views
Last Modified: 2014-02-11
I am attempting to allow a user to reset the default value of a combo box based on its displayed value.  I have 4 combo boxes of differing types to do this with (one integer, 3 text).  For example, I want the user to be able to reset a default year on their own, and a combo box with available years is already displayed.  Functionally, I want the user to select a year, push a "set to default" button which will then reset that users default value to the displayed value.  Each user has their own "front-end" copy of access (everything except tables - which are linked), so this should be easy but I'm stumped.  Here is what I attached to the "set to default" button:

Private Sub set_default_yr_Click()

Dim reset_yr As Integer

Me.CurYear.Requery
reset_yr = Me.CurYear.Value
Me.CurYear.DefaultValue = reset_yr
Me.CurYear.Requery



End Sub

Oddly, my immediate window shows a null value for reset_yr after I push the set to default button.  Thanks for your help!
0
Comment
Question by:jwandmrsquared
3 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 39818080
Give this a try:

Private Sub set_default_yr_Click()

Dim reset_yr As Integer

Me.refresh
reset_yr = Me.CurYear.Value
Me.CurYear.DefaultValue = reset_yr
Me.CurYear.Requery

End Sub

Open in new window

0
 
LVL 10

Accepted Solution

by:
Gozreh earned 500 total points
ID: 39818131
You can only set the DefaultValue if you change it in design view of the
form and then save the form.

if you change it with VBA it will only be available till you close the form.

so if you want want it should stay even you close it, you will need to store it in a table or in the registry.
0
 

Author Closing Comment

by:jwandmrsquared
ID: 39850735
Not what I wanted to hear but at least it prevents hours of searching.
0

Featured Post

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.

Question has a verified solution.

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

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…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

773 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