Allow User to Permanently Change Default Value of Combo Box

  • Thread starter Thread starter Gail
  • Start date Start date
G

Gail

Hello All,

Thank you for this really helpful forum.

I want to allow the users of my database to click a button
that would enable them to permanently change the default
value of a combo box (until the next time they click the
button). In other words, the default value of the combo
box would remain even after closing and re-opening the
form. I have tried several different ways but have been
unsuccessful in getting Access to put a string in the
Default Value property box--maybe this is not possible?

Code such as the following (from Dev Ashish of Access Web)
only works while the form remains open, once the form is
closed and re-opened the default value is gone:

const cQuote = """"
me!Control.DefaultValue = cQuote & meControl.Value & cQuote

I don't think I can change the default value of the table
field because my tables are linked, but if anyone knows a
way, I will try it.

Thanks again,

Gail
 
Hummmm....I would think that you would also need to save the form with the
changed value through VBA and also perhaps set AllowDesignChanges=True. OK I
just tried that and it didn't work, the changes weren't saved.

All right 2nd try. Here's what I came up with that does appear to work:

Dim strName As String
Dim strDefault As String

Let strName = Me.Name
Let strDefault = Me.txtDefault.Value
Call Access.DoCmd.OpenForm(FormName:=strName, View:=acDesign,
Windowmode:=acWindowNormal)
Let Forms![Form Test Default].txtDefault.DefaultValue = """" &
strDefault & """"
Call Access.DoCmd.Save(ObjectType:=acForm, ObjectName:=strName)
Call Access.DoCmd.OpenForm(FormName:=strName, View:=acNormal,
Windowmode:=acWindowNormal)
Let Forms![Form Test Default].txtDefault.Value = strDefault


Note that this actually programmatically reopens the form in design view and
makes the change. If you use this technique you'll need to make sure that
any data that needs to be saved IS saved before calling the code. Hope this
helps.



Jon
 
Jon,

Your solution works like a charm, simple and effective.
Only minor tweaking to make it work smoothly on the form.

Thx,

Gail
 
Glad that I could help! I've gotten a lot out of these news groups myself so
I try to "give back" whenever I can.
 
Back
Top