Using AND statement with if Statement

Leeman

Registered User.
Local time
Today, 00:52
Joined
Jan 6, 2010
Messages
11
IF ELSE Statements issue and ISNULL statements

I have a piece of code which looks for a delimeter "/" in a string (e.g. Smith/John) and if it find the "/" then it splits these two strings at the "/"

If the delimiter is not found then the it goes to the next record. however i dont want it to do this, only if the cell is NULL.

If the string has just surname, then i wnat it to update the cell and then go to next record.

The field is called Fullname, and the code below is the original (working) code

Code:
Do Until rs.EOF
            numCols = 0
            Dim pos As Long
            pos = InStr(rs("Fullname"), "/")
            If pos = 0 Then GoTo NextRow
            rs.Edit
            rs("Surname") = Mid(rs("FullName"), 1, pos - 1)
            remnant = Mid(rs("Fullname"), pos + 1)
            words = Split(remnant)
I am trying to change this so it if the delimter is not found but the cell is not empty then the surname = fullname and then goes to next row, but iof the "/" is not found AND the cell is empty i want it to go to next record.

Code:
   Do Until rs.EOF
            Dim pos As Long
            pos = InStr(rs("Fullname"), "/")
            If rs("Fullname") = NULL Then GoTo NextRow
            If pos = 0 AND rs("Fullname") = IS NOT NULL then
             rs.edit
            rs("Surname") = rs("Fullname")
            GoTo NextRow 
             Else
            rs("Surname") = Mid(rs("Fullname"), 1, pos - 1)
            remnant = Mid(rs("Fullname"), pos + 1)
.
.
Or maybe somehting like this?

Code:
Do Until rs.EOF
            Dim pos As Long
            If rs("FullName") = "" Then GoTo NextRow
            pos = InStr(rs("FullName"), "/")
            rs.Edit
            If pos = 0 Then
            rs("Surname") = rs("FullName") GoTo NextRow
            rs("Surname") = Mid(rs("FullName"), 1, pos - 1)
            remnant = Mid(rs("FullName"), pos + 1)
I think i have my IF ELSE statements in a mess. I am getting a Loop without Do error.
 
Last edited:
Actually, I just got this working myself :)

Code:
   Do Until rs.EOF
            Dim pos As Long
            If rs("Fullname") = "" Then GoTo NextRow
            pos = InStr(rs("Fullname"), "/")
            rs.Edit
            If pos = 0 Then
            rs("Surname") = rs("Fullname")
            Else: rs("Surname") = Mid(rs("Fullname"), 1, pos - 1)
            End If
            remnant = Mid(rs("Fullname"), pos + 1)
            remnant = ParseFirstComp(remnant)

Although it does place the full name in both Surname and the remnant fields, it is working and doesnt miss out on cell that have no "/" in them :)
 

Users who are viewing this thread

Back
Top Bottom