Check if string contains numeric characters (1 Viewer)

supmktg

Registered User.
Local time
Today, 03:11
Joined
Mar 25, 2002
Messages
360
Is there an easy way in VBA to loop through a recordset and determine if the text string in a text field includes numeric characters?

I'm trying to do something like this:

Code:
Do Until rst.EOF

rst.Edit
If Left(rst!FldText,10) contains any numeric characters Then
rst!FldType = "Mixed"
ElseIF Left(rst!FldText,10) contains "PO" Then
rst!FldType = "PO"
Else
rst!FldType = "Std"
End If
rst.Update

Any help would be greatly appreciated,
Sup
 

MarkK

bit cruncher
Local time
Today, 01:11
Joined
Mar 17, 2004
Messages
8,186
Rather than looping through the recordset you'd probably get way better performance to run a few update queries, something like . . .

Code:
With CurrentDb
   .Execute _
      "UPDATE YourTable " & _
      "SET fldType = 'STD'"
   .Execute _
      "UPDATE YourTable " & _
      "SET fldType = 'PO' " & _
      "WHERE Left(fldText, 10) LIKE '*PO*'"
   .Execute _
      "UPDATE YourTable " & _
      "SET fldType = 'Mixed' " & _
      "WHERE Left(fldText, 10) LIKE '*#*'"
End With
. . . or better still, just calculate the field in the query, and don't store it or update it . . .
SELECT fldText,
IIf(Left(fldText, 10) LIKE "*#*", "Mixed", IIf(Left(fldText, 10) LIKE "*PO*", "PO", "STD")) As fldType
FROM YourTable
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 18:11
Joined
Jan 20, 2009
Messages
12,854
In addition to Lagbolt's solution I thought it worth mentioning about how to use Regular Expressions in Access queries.

REs are very versatile for finding patterns in strings. They can manage much more complex patterns than the sql wildcards.

http://www.access-programmers.co.uk/forums/showthread.php?t=254486
 

Users who are viewing this thread

Top Bottom