text box default value from form

  • Thread starter Thread starter JIM.H.
  • Start date Start date
J

JIM.H.

Hello,
I need to have a text field in my form that will have a
default value as one of the field in the form. I tried to
use control source as the value of field but I could not
change my new text box value because it is linked to
source value. It should not be linked to another field, I
just need to have it there as default value and user
should be able to change it.
Thanks,
Jim.
 
Place this in the OnCurrent() event of your form;

Dim str as String
str = "='" & Nz(Me!ctlToUse,"") & "'"
Me!myTxtBox.DefaultValue = str


Change 'ctlToUse' and 'myTxtBox' to the names of the
controls on yor form. As a side note, if 'myTxtBox' has a
ControlSource then the default value will only be
displayed on the 'New' record. Good luck.
 
Thanks Elwin,
I could not get it work. MYmyTxtBox has value 1 but not
the value of MYctlToUse. If it makes difference, I am
caling this from from another form through a button.
 
Yes it does matter where you're callin it from :)

If you want to use a button then call it from the OnClick
event of that button. I've made the code more explicit to
decrease the chance for error, but feel free to simplify
it once you understand it.

Private Sub myCommandButtonName_Click()
Dim frmFrom as Form
Dim frmTo as Form
Dim ctlFrom as Control
Dim ctlTo as Control
Dim str as String
Set frmFrom = Forms!FormWithValueToUse
Set ctlFrom = frmFrom!CtlWithValueToUse
Set frmTo = Forms!FormDisplayingDefault
Set ctlTo = frmTo!CtlDisplayingDefault
str = "='" & Nz(ctlFrom,"") & "'"
ctlTo.DefaultValue = str
End Sub
 
Back
Top