Solved

Set default value of Combo box using displayed combo box value

Posted on 2014-01-29
3
739 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
Comment Utility
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
Comment Utility
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
Comment Utility
Not what I wanted to hear but at least it prevents hours of searching.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…

744 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

17 Experts available now in Live!

Get 1:1 Help Now