I am practicing VBA for Access 2010.
I read all the suggested post regarding my post but did not find anything specific. I know how to move specific characters in a string, what I do not know is how I can remove specific character that equals to something.
I want to move the character 1 or 1- from telephone numbers if one is there.
Example: 17188888888 to 7188888888 or 1-7188888888 to 7188888888
I am trying to use an if statement starting first with just removing the 1.
The phone number is entered as a string not numbers.
This is what I have started: I am getting an error message that RemoveFirstChar is ambiguous.
Public Function RemoveFirstChar(RemFstChar As String) As String
If Left(RemFstChar, 1) = "1" Then
RemFstChar = Replace(RemFstChar, "1", "")
End If
RemoveFirstChar = RemFstChar
End Function
To remove the string's first character, we can use the built-in substring() function in R. The substring() function accepts 3 arguments, the first one is a string, the second is start position, third is end position.
I have tested your function in Access 2010 and it worked just fune.. You can also use this code:
Public Function RemoveFirstChar(RemFstChar As String) As String
Dim TempString As String
TempString = RemFstChar
If Left(RemFstChar, 1) = "1" Then
If Len(RemFstChar) > 1 Then
TempString = Right(RemFstChar, Len(RemFstChar) - 1)
End If
End If
RemoveFirstChar = TempString
End Function
There is nothing particularly wrong with your code, the "ambiguous" error message in this context is very likely to be because you have another sub or function in a different module with the same name. Search to find the duplicate name.
If you put the function in the module belonging to a form or report, it is probably best to skip "Public". If you intend the function to be used by several forms, create a new module that is not attached to a form and put the functions that are intended for all forms and reports in that.
It is nearly always good to provide the full error message and error number.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With