Default Value

  • Thread starter Thread starter Joanne
  • Start date Start date
J

Joanne

I have a field that I would like to have this in as it's default
value:

-B/O

Then when the user goes to the field I would like them to be able to
add a numeric string in front of this default, something like this:

239401-B/O

I am simply trying to save some repetitive keyboarding.

Any help is as always appreciated. Finding that someone has read and
answered your question is a lot like getting a surprise gift.

You mvps/contributors are great

Joanne
 
You can't do this in a report, so I assume that you want to do it in a form?

One way is to use the AfterUpdate event of the textbox to add the trailing
text to whatever the user enters:

Private Sub TextBoxName_AfterUpdate()
Const strAddText As String = "-B/O"
If Right(Me.TextBoxName.Value, Len(strAddText)) <> strAddText Then _
Me.TextBoxName.Value = Me.TextBoxName.Value & strAddText
End Sub


Or you can put the default text in the textbox and then position the cursor
to the left of the first character, using the GotFocus event of the textbox:

Private Sub TextBoxName_GotFocus()
Const strAddText As String = "-B/O"
If Len(Me.TextBoxName.Value & "") = 0 Then
Me.TextBoxName.Value = strAddText
Me.TextBoxName.SelStart = 0
Me.TextBoxName.SelLength = 0
End If
End Sub
 
Back
Top