Replace function

access09

Registered User.
Local time
Yesterday, 23:30
Joined
Apr 14, 2009
Messages
40
I am trying to use a replace function in VBA to run a query but I dont know how to reference it in VBA in order for it to work.

Here is my code where I ahve tried to use to get rid of certain characters from people's name:

Code:
Public Function GetName(AnyText As String, bFlag As Boolean) As String
GetName = Replace(AnyText, "*", "")
Dim nIndex As Integer
nIndex = InStr(AnyText, "/")
If nIndex = 0 Then
   If bFlag = False Then   'Surname
      GetName = ""
   Else
      GetName = AnyText  'Forename
   End If
   Exit Function
Else
   If bFlag = True Then
      GetName = Left(AnyText, nIndex - 1)
   Else
      GetName = Mid(AnyText, nIndex + 1)
End If
End If
End Function

Any ideas what I am doing wrong with the replace function??
 
I cannot see anythink wrong with the replace, this little test I ran incase I was wrong worked perfectly

Code:
Function rep(fld) As String

rep = Replace(fld, "ltd", "")
rep = Replace(rep, "plc", "")

End Function

Brian
 

Users who are viewing this thread

Back
Top Bottom