BUTTON change default value

L

lmv

I have a form with a specific city set as default on a combobox field

1=Louisville

Most of the time I want it there.
I'd like to put a button that allows user to change that to a different city
without going to design view.
I can make a form to pop up with the city list but I don't know the cmd to
put on the button to direct the button to change the coding on the field
changing the default.

form name: Territory Numbers
cbobox: cboCity
default:1

any ideas
TIA!!
 
T

Tom Wickerath

Hi Imv,

You can use code similar to this:

Private Sub cmdSetDefaultCity_Click()
On Error GoTo ProcError

If Not IsNull(Me.cboCity) Then
Me.cboCountry.DefaultValue = Me.cboCity
End If

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure cmdSetDefaultCity_Click..."
Resume ExitProc
End Sub

Note: If the control source is a text value, then use this line of code
instead:
Me.cboCountry.DefaultValue = "'" & Me.cboCity & "'"

However, if you want to allow the user's choice to persist the next time
they open the form, then you will likely want to save the default value to a
local table, and set it programatically the next time the form is opened.


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 

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

Similar Threads

Start at the end? 1
Auto value 2
Form help 4
Combo box help! 3
Filter based on value in combo box 1
How to change Default Value on Form 3
Combo Boxes 2
Radio Button Default Value Problem 10

Top