Partial defaul value?

  • Thread starter Thread starter Charlie
  • Start date Start date
C

Charlie

I have a form field in which the input is always a six-
digit number preceeded by the letter "P". What is the
proper expression for setting the default value so that
the "P" appears with the insertion point behind it (so
that when I tab to this field I can just type the number
without having to type the letter repeatedly).

This seems like it should be a no-brainer (what can I
say?).
 
I have a form field in which the input is always a six-
digit number preceeded by the letter "P". What is the
proper expression for setting the default value so that
the "P" appears with the insertion point behind it (so
that when I tab to this field I can just type the number
without having to type the letter repeatedly).

Set the "Default Value" property for the control on the form to "P" and in the
control's "On Enter" event procedure, enter code like the following:

Me.ControlName.SelStart = Len(Me.ControlName.Value & "")

Remember to replace "ControlName" with the name of the control on your form.
 
I have a form field in which the input is always a six-
digit number preceeded by the letter "P". What is the
proper expression for setting the default value so that
the "P" appears with the insertion point behind it (so
that when I tab to this field I can just type the number
without having to type the letter repeatedly).

This seems like it should be a no-brainer (what can I
say?).

Well, this can be done... but how about not storing the P at all!?

Just set the Format property of the field to

"P000000"

A literal P will be tacked on for display purposes; no need to waste
space in the table for it.

If you want to store the letter (it's not necessary but can sometimes
be convenient) use the SelStart and SelLength properties of the form
textbox. Set the Default property to

"P000000"

and set the SelStart to 2, and SelLength to 6. When you tab into the
field it will have the insertion point at the second byte and the six
zeros highlighted for overtyping. It'll be the user's responsibility
to type in the leading zeros.
 
Back
Top