Solved

Set default value of Combo box using displayed combo box value

Posted on 2014-01-29
3
754 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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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.

739 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