Partial defaul value?

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?).
 
B

Bruce M. Thompson

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.
 
J

John Vinson

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.
 

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

Top