Text Box Coding

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

What coding would accomplish this in a text box?

When you enter or paste a number like this:

000027250546897

It will then become this:

27250546897

On the after update or whichever is event most appropriate.

Thanks
Curtis
 
If this text box is bound to a Number field, you don't have to do anything.
Access will remove the leading zeros for you.

If the control is unbound, set its Format property to:
General Number
Access will recognise it as a number (provided you paste a number) and
remove the leading zeros.

If you need to code it, use Val().
Test if is IsNull() first.
 
Yes it is bounded, but the box is text, I tried number formats before and
nothing works as the number must be like that below, no commas, decimals, etc.

Curtis
 
Yes it is bounded, but the box is text, I tried number formats before and
nothing works as the number must be like that below, no colmas, decimals, etc.

Curtis
 
Curtis Stevens said:
What coding would accomplish this in a text box?

When you enter or paste a number like this:

000027250546897

It will then become this:

27250546897

On the after update or whichever is event most appropriate.

Thanks
Curtis

TheString = Textbox.Value
ls = Len(TheString)
For i = 1 To ls
If Val(Mid(TheString, i, 1)) > 0 Then
Exit For
End If
Next
If i < ls Then Textbox.Value = Mid(TheString, i)
 
This example takes leading digits, kills any sign, and drops the decimal
point:

Private Sub Text0_AfterUpdate()
If Not IsNull(Me.Text0) Then
Me.Text0 = Replace(Abs(Val([Text0])), ".", "")
End If
End Sub
 
Am I missing something here, should one of the number formats for the text
box in the table work the way I want it to? Tried byte, single, etc.

Curtis

This example takes leading digits, kills any sign, and drops the decimal
point:

Private Sub Text0_AfterUpdate()
If Not IsNull(Me.Text0) Then
Me.Text0 = Replace(Abs(Val([Text0])), ".", "")
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Curtis Stevens said:
Yes it is bounded, but the box is text, I tried number formats before and
nothing works as the number must be like that below, no commas, decimals,
etc.

Curtis
 
Am I missing something here?

If this is a Text field in the table (as I understood you to say), you don't
get to specify Byte, Single, etc.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Curtis Stevens said:
Am I missing something here, should one of the number formats for the text
box in the table work the way I want it to? Tried byte, single, etc.

Curtis

This example takes leading digits, kills any sign, and drops the decimal
point:

Private Sub Text0_AfterUpdate()
If Not IsNull(Me.Text0) Then
Me.Text0 = Replace(Abs(Val([Text0])), ".", "")
End If
End Sub

message
Yes it is bounded, but the box is text, I tried number formats before
and
nothing works as the number must be like that below, no commas,
decimals,
etc.

Curtis


If this text box is bound to a Number field, you don't have to do
anything.
Access will remove the leading zeros for you.

If the control is unbound, set its Format property to:
General Number
Access will recognise it as a number (provided you paste a number) and
remove the leading zeros.

If you need to code it, use Val().
Test if is IsNull() first.

message
What coding would accomplish this in a text box?

When you enter or paste a number like this:

000027250546897

It will then become this:

27250546897

On the after update or whichever is event most appropriate.

Thanks
Curtis
 
The current text box is setup as text. I was asking if I change it to
number's format, which one do I select as have tried those listed and they
don't work.

Would the numbers field type work or should I stick with text and do the
coding provided?

Curtis

Am I missing something here?

If this is a Text field in the table (as I understood you to say), you don't
get to specify Byte, Single, etc.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Curtis Stevens said:
Am I missing something here, should one of the number formats for the text
box in the table work the way I want it to? Tried byte, single, etc.

Curtis

This example takes leading digits, kills any sign, and drops the decimal
point:

Private Sub Text0_AfterUpdate()
If Not IsNull(Me.Text0) Then
Me.Text0 = Replace(Abs(Val([Text0])), ".", "")
End If
End Sub

message
Yes it is bounded, but the box is text, I tried number formats before
and
nothing works as the number must be like that below, no commas,
decimals,
etc.

Curtis


If this text box is bound to a Number field, you don't have to do
anything.
Access will remove the leading zeros for you.

If the control is unbound, set its Format property to:
General Number
Access will recognise it as a number (provided you paste a number) and
remove the leading zeros.

If you need to code it, use Val().
Test if is IsNull() first.

message
What coding would accomplish this in a text box?

When you enter or paste a number like this:

000027250546897

It will then become this:

27250546897

On the after update or whichever is event most appropriate.

Thanks
Curtis
 
In your table, use a field of type Number.
In general, use Long Integer for whole numbers, Double from fractional
numbers, and Currency if it's dollars and cents (and some other cases where
you need no more than 4 decimal places.)

Integers are okay for whole number up to 32767.

Bytes are of very limited use.

Leave the Format property of this field blank in table design.

A text box bound to this field will then suppress leading zeros.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Curtis Stevens said:
The current text box is setup as text. I was asking if I change it to
number's format, which one do I select as have tried those listed and they
don't work.

Would the numbers field type work or should I stick with text and do the
coding provided?

Curtis

Am I missing something here?

If this is a Text field in the table (as I understood you to say), you
don't
get to specify Byte, Single, etc.

message
Am I missing something here, should one of the number formats for the
text
box in the table work the way I want it to? Tried byte, single, etc.

Curtis


This example takes leading digits, kills any sign, and drops the
decimal
point:

Private Sub Text0_AfterUpdate()
If Not IsNull(Me.Text0) Then
Me.Text0 = Replace(Abs(Val([Text0])), ".", "")
End If
End Sub

message
Yes it is bounded, but the box is text, I tried number formats
before
and
nothing works as the number must be like that below, no commas,
decimals,
etc.

Curtis


If this text box is bound to a Number field, you don't have to do
anything.
Access will remove the leading zeros for you.

If the control is unbound, set its Format property to:
General Number
Access will recognise it as a number (provided you paste a number)
and
remove the leading zeros.

If you need to code it, use Val().
Test if is IsNull() first.

message
What coding would accomplish this in a text box?

When you enter or paste a number like this:

000027250546897

It will then become this:

27250546897

On the after update or whichever is event most appropriate.

Thanks
Curtis
 
Back
Top