Text Field

S

Sean

I ahev a text field in my table that display quantities like this, (5 EA, 16
PAC, 1,000 EA). There is always a space after the number. How do I strip
everything to the right of the space (i.e. EA, PAC) so I can then convert
this field to a number?
Thanks,
 
K

KARL DEWEY

Left([YourTextField], InStr([YourTextField]," ")-1)

and for the right part use --
Mid([YourTextField], InStr([YourTextField]," ")+1)
 
J

John W. Vinson

I ahev a text field in my table that display quantities like this, (5 EA, 16
PAC, 1,000 EA). There is always a space after the number. How do I strip
everything to the right of the space (i.e. EA, PAC) so I can then convert
this field to a number?
Thanks,

It's not actually necessary to do so: Val([fieldname]) will extract just the
leading number.
 
R

raskew via AccessMonster.com

The following will remove all non-numeric characters from a string

Code:
Public Function fSaveNumer2(pPhone As String) As String
'purpose:  Removes all non-numeric characters from a
'          string.
'coded by: raskew
'calls:    IsNumeric()
'Input:    ? fSaveNumer2("(800)-555-1212")
'Returns:  8005551212
'

Dim strHold As String
Dim strKeep As String
Dim intLen  As Integer
Dim n       As Integer

strHold = pPhone
intLen = Len(strHold)
For n = 1 To intLen

Next
On Error GoTo E_Handle

fExit:
On Error Resume Next

Exit Function
E_Handle:
MsgBox Err.Description & vbCrLf & "fSaveNumer2", vbOKOnly + vbCritical,
"Error: " & Err.Number
Resume fExit
End Function

HTH - Bob
I ahev a text field in my table that display quantities like this, (5 EA, 16
PAC, 1,000 EA). There is always a space after the number. How do I strip
everything to the right of the space (i.e. EA, PAC) so I can then convert
this field to a number?
Thanks,

It's not actually necessary to do so: Val([fieldname]) will extract just the
leading number.
 
J

John W. Vinson

The following will remove all non-numeric characters from a string

Code:
Public Function fSaveNumer2(pPhone As String) As String[/QUOTE]

Just so the OP knows that this function returns a string, and they must use
Val() or CInt() or CCur() to convert it to a number (or currency).
 

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