How to add leading zeros and REFRESH the screen after user tab (or move) out of the f

path479

Registered User.
Local time
Tomorrow, 02:43
Joined
Jan 4, 2016
Messages
22
Our database has a text field which the user is required to enter a numeric project id via a form. Most of the project id is less than 6 digits long, however we need to add leading zeros to ensure it is stored as 6 digits.

How do we add the leading zeros and, more importantly, REFRESH the screen so that the 6 digits long project id is reflected on screen/form as soon as the user tab (or click/move) out of the field in the form?

We have a separate "Save" button
 
Set ProjectId field and textbox on form format property to 000000.
 
Do you mean for the text box field, go to "Property Sheet" -> "Format" tab -> "Format" field, and set it to 000000?

It doesn't seem to work. The 000000 does appear in the field. However as soon as I click into the field, it revert back to all spaces.

I have also tried setting the "Default Value" field under the "Data" tab to 000000, but unfortunately also doesn't work.

Have I missed something?
 
Do you mean for the text box field, go to "Property Sheet" -> "Format" tab -> "Format" field, and set it to 000000?

It doesn't seem to work. The 000000 does appear in the field. However as soon as I click into the field, it revert back to all spaces.

It work for me but I also have set field format in table to 000000. Open table in design mode and set this field format property to 000000 and see if it works.

I have also tried setting the "Default Value" field under the "Data" tab to 000000, but unfortunately also doesn't work.

Well, don't. You don't want default value to be 0, do you?
 
is the field text, or numeric?

assuming text, then
a) in the beforeupdate event for control ensure the value is numeric
b) in the after update event, you can have something like
mycontrol = right("000000" & trim(mycontrol),6)

the value will then be stored as text with leading zeroes.
 
you can also do it in the controls Lost Focus event:

Private Sub yourTextBoxName_LostFocus()
Dim strText As String
strText = Trim(Me.yourTextBoxName & "")
If strText <> "" then
Me.yourTextBoxName = Format(strText, "000000")
End If
End Sub
 
Thank you so much arnelgp! Thank you for pointing out I can also use the Lost Focus event. I was a bit confused as to what each of the event means. After seeing your post I did more research and now have better understanding on Lost Focus and After Event.
 

Users who are viewing this thread

Back
Top Bottom