Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add on Coding to skip the blank record 2

Status
Not open for further replies.

Tamrak

MIS
Jan 18, 2001
213
US
Good afternoon,

Can you assist me with this function?

I have several data in the table that have a format + + + + between each string. Sometimes, it looks like, Jeff+Smith+Barber+50+25 etc. Anyway, I can get the information that I am looking for.

The following is the code. It is working fine.

********************
Function TestString(FieldString As Variant) As String
Dim SplitEm
SplitEm = Split(FieldString, "+")
If UBound(SplitEm) >= 5 Then
TestString = SplitEm(5)
Else
TestString = SplitEm(UBound(SplitEm))
End If
End Function
*************************

Let's say the field name called, employeedata. I created a query, DataTest:Teststring([employeedata]).

However, the code generates an error when it hits the blank record. Can you assist in writing another if statement to skip the blank record? Otherwise, '94' error continues to populate.

Thanks a lot.

 
You could check for NULL's or just return blank if it's NULL, I've gone for option 2, try something like:
Code:
Function TestString(FieldString As Variant) As String
Dim SplitEm
SplitEm = Split(Nz(FieldString,"+"), "+")
If UBound(SplitEm) >= 5 Then
   TestString = SplitEm(5)
Else
   TestString = SplitEm(UBound(SplitEm))
End If
End Function
Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Code:
Function TestString(FieldString As Variant) As String
Dim SplitEm

if Len (FieldString & "") > 0 Then
  SplitEm = Split(FieldString, "+")
  If UBound(SplitEm) >= 5 Then
     TestString = SplitEm(5)
  Else
     TestString = SplitEm(UBound(SplitEm))
  End If
Else
  TestString = ""
End If
End Function

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top