Need help with combo box default selection

N

Nick D

I have a combo box that selects 1 of 7 different values.
I want to how to write the code so that I can have the
last selection made on that form saved so it can become
the default the next time I open the form. I have tried
this code and it doesn't seem to work:

Choose_MESD_Employee.DefaultValue = """" &
Me.Choose_MESD_Employee & """"
DoCmd.Save acForm, Me.Name

Thank you,

Nick
 
G

Gary Miller

Nick,

Try putting the following in the AfterUpdate event of the Form but use the
name of your combo box...

Me!cboYourCombo.DefaultValue = Me!cboYourCombo.Value

Should work record to record though I am not sure if it will persist once
you close the form.

Gary Miller
 
N

Nick D.

It didn't work...I tried that one also before. I got to
the previous code to make it work for a string. I save
the value using:

ComboBox.DefaultValue =
"""" & Me.ComboBox & """"

DoCmd.Save acForm, Me.Name


but what i think happens is that Access write a blank
default over it when I reopen the form. It seems as
though I can't get around it with out some heavy coding.
Let me know if you think of something else.

Thanks for your help,

Nick
 
G

Gary Miller

Very Interesting!!!

I did some playing around with a test form by opening it in
design, setting a control default that was previously blank,
testing the default. All is fine. Close the form using
acformsave after forcing a previous save with a docmd.save.
I reopened in design again tested for the default and got a
blank message box.

You are right. It seems to be ignoring the programmatic
default change.

May want to repost again as I am out of ideas on this one
unless it would be to try the same thing at the table level
with a blank on the form so the default would be carried
over to the form. Don't have the time to play with that at
the moment.

Gary
 
A

Adrian Jansen

I think your only solution is to save the setting in either a table within
the database, or in the Windows registry. For just one ( or a few ) values,
the registry works quite well. Look up SaveSetting and GetSetting in Help.

--
Regards,

Adrian Jansen
J & K MicroSystems
Microcomputer solutions for industrial control
 
G

Gary Miller

Adrian,

Great suggestion. If you can't fight it work around it. Save
it and pull it up when the form is loaded.

Gary Miller
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top