I have a field path in my app.
How can ik check through VBA that the last character is a \ and if not
pressent a messagebox telling that a \ is missing at the end?
Thanx for any tips!
Regards,
Harmannus
Dim pos as Integer
pos = Instr(Right(StringToSearch,1 ), "/")
If pos > 0 Then 'Last char not a /
StringToSearch = StringToSearch & "/" 'Add the slash automatically
End If
--
James Goodman
MCSE MCDBA
http://www.angelfire.com/sports/f1pictures/
"Harmannus" <hexe...@hotmail.com> wrote in message
news:ugZp3Qg9...@TK2MSFTNGP09.phx.gbl...
I added your code to the after update event of the myPath field but get a
error "argument not optional.". What did i do wrong? Thanx in advance for
your help!
Private Sub MyPath_AfterUpdate()
Dim pos As Integer
pos = InStr(Right(Me.MyPath, , 1), "/")
If pos > 0 Then 'Last char not a /
Me.MyPath = Me.MyPath & "/" 'Add the slash automatically
End If
End Sub
Regards,
Harmannus
"James Goodman" <ja...@norton-associates.REMOVE.co.uk> wrote in message
news:c0vigb$llk$1...@hercules.btinternet.com...
There is an extra comma in the Right() function
pos = InStr(Right(Me.MyPath, , 1), "/")
^^
should be
pos = InStr(Right(Me.MyPath, 1), "/")
BTW, since the path is entered, you might need to check for (and remove) a space as the last char, also.
pos = InStr(Right(Trim(Me.MyPath), 1), "/")
The Trim() function removes leading and trailing spaces.
Steve
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)
----- Harmannus wrote: -----
Thanx for the reply.
Still can't get the code to work.
Private Sub Path_BeforeUpdate(Cancel As Integer)
Dim pos As Integer
pos = InStr(Right(Trim(Me.Path), 1), "\")
If pos > 0 Then 'Last char not a \
Me.Path = Me.Path & "\" 'Add the slash automatically
End If
End Sub
A path without a \ doesnt'get a \ added. A path with a \ gives a error.
Any suggestion on how to correct this?
Regards,
Harmannus
"sanfu" <sanfu_SPAM@BLOCKER_techie.com> wrote in message
news:E92E310F-0232-4574...@microsoft.com...
---------
Private Sub path_AfterUpdate()
Dim pos As Integer, str As String
pos = InStr(Right(Trim(Me.Path), 1), "\")
If pos < 1 Then 'Last char not a \
Me.Path = Me.Path & "\" 'Add the slash automatically
End If
End Sub
-------
NOTE: I had to change the "If pos" to If pos < 1 ; which means the "\"
was not found.
this also works
------------
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim pos As Integer, str As String
pos = InStr(Right(Trim(Me.Path), 1), "\")
If pos < 1 Then 'Last char not a \
Me.Path = Me.Path & "\" 'Add the slash automatically
End If
End Sub
-------
--