I haven't tested, but you don't put square brackets around variable names.
As well, assuming midWord is supposed to contain Rebecca L Steward in your
example, it should be
midWord = Mid([varSamp_Rest], i + 4)
You also need to check that it did, in fact, find FOR in the text. If it
didn't, i will be 0, and Left will not work with a negative number.
i = InStr(varSamp_Rest, "FOR ")
If i > 0 Then
midWord = Trim(varSamp_Rest, i + 4)
sRest = Trim(Left(varSamp_Rest, i - 1))
Else
midWord = vbNullString
sRest = Trim(varSamp_Rest)
Else
rst!Name = midWord
rst!Name4 = [sRest]
If that's not the problem, on which line of code is it actually failing?
--
Doug Steele, Microsoft Access MVP
(no private e-mails, please)
N.Ordiers said:
Ofer,
I am in similar dilemma, I trying to split names that have "FOR" on it
such
as "KRISTINE STEWARD FOR REBECCA L STEWARD". I have try the following
code:
-Code below
Do While Not rst.EOF
rst.Edit
varSamp_Rest = rst!Samp_Rest
i = InStr([varSamp_Rest], "FOR ")
midWord = Right([varSamp_Rest], i + 2)
sRest = Left([varSamp_Rest], i - 1)
rst!Name = Trim(midWord) 'Var Char
rst!Name4 = Trim([sRest])
rst.Update
rst.MoveNext
Loop
rst.Close-End code
This has failed, with the "Invalid procedure or argument" but it works
using
blank spaces?
I try changing the above code to use the split function but got nowhere.
Any
help is appreciated
Neil
:
Use the split function to split the string into parts
Dim MyString As String
MyString = "TestID_TestMachineName_CIF_20070302-013022.txt"
MyString = Replace(MyString , ".txt", "")
' First part
Split(MyString ,"_")(0)
' Second part
Split(MyString ,"_")(1)
' Third part
Split(MyString ,"_")(2)
' Date
Left(split(MyString ,"_")(3),Instr(split(MyString ,"_")(3),"-")-1)
' Time
Mid(split(MyString ,"_")(3),Instr(split(MyString ,"_")(3),"-")+1)
--
Good Luck
BS"D
:
I have code that allows my users to grab the name of text files. What I
need
to do now is parse out the text file name into several pieces. Here is
an
example of a file:
TestID_TestMachineName_CIF_20070302-013022.txt
The file will always have the same structure. I need the 3 text values
that
are separated by "_". The 2 values at the end of the string are date
and time
(separated by "-"). I don't care about the ".txt" at the end.
Any ideas as how I can do this?
Much thanks!!
Clint