Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Set default value of Combo box using displayed combo box value

Posted on 2014-01-29
3
Medium Priority
?
761 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
[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 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 2000 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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

722 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