G
Guest
Hi, This is the first time I am working on something with VBA. I have
inserted 1 Module without any problems but this one, I am getting anything.
The code will change the first letter to caps. I inserted the following
code into a Modeule and named it, fFirstUpper.
When I go to the Control Source of a textbox in a form or report, I am
getting an error. #Name? in a form and a Report a Parameter and then #Error.
=fFirstupper([Lastname]) I tried this in a text called lastname and a text1.
Thanks
Function fFirstUpper(ByVal vstrIn As String) As String
Const cSpace As String = " "
Dim strOut As String
Dim strCur As String
Dim lngPos As Long
Dim blnNewWord As Boolean
blnNewWord = True
strOut = ""
For lngPos = 1 To Len(vstrIn)
strCur = Mid(vstrIn, lngPos, 1)
If strCur = cSpace Then
strOut = strOut & strCur
blnNewWord = True
Else
If blnNewWord Then
strOut = strOut & UCase(strCur)
blnNewWord = False
Else
strOut = strOut & LCase(strCur)
'strOut = strOut & strCur
'if you want to keep case of characters within a word
End If
End If
Next lngPos
fFirstUpper = strOut
End Function
inserted 1 Module without any problems but this one, I am getting anything.
The code will change the first letter to caps. I inserted the following
code into a Modeule and named it, fFirstUpper.
When I go to the Control Source of a textbox in a form or report, I am
getting an error. #Name? in a form and a Report a Parameter and then #Error.
=fFirstupper([Lastname]) I tried this in a text called lastname and a text1.
Thanks
Function fFirstUpper(ByVal vstrIn As String) As String
Const cSpace As String = " "
Dim strOut As String
Dim strCur As String
Dim lngPos As Long
Dim blnNewWord As Boolean
blnNewWord = True
strOut = ""
For lngPos = 1 To Len(vstrIn)
strCur = Mid(vstrIn, lngPos, 1)
If strCur = cSpace Then
strOut = strOut & strCur
blnNewWord = True
Else
If blnNewWord Then
strOut = strOut & UCase(strCur)
blnNewWord = False
Else
strOut = strOut & LCase(strCur)
'strOut = strOut & strCur
'if you want to keep case of characters within a word
End If
End If
Next lngPos
fFirstUpper = strOut
End Function