BUTTON change default value

  • Thread starter Thread starter lmv
  • Start date Start date
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!!
 
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
__________________________________________
 
Back
Top