Full Version: replace code
UtterAccess Forums > Microsoft® Access > Access Forms
fullyunknown
I have a form when a user clicks update it starts a series of events. one of the events is changing a file name to fit what I need to enter it into database.
I use to use filenames that look like the following--> CSN.pdf
CODE
  lngLen = Replace(f1.Name, ".pdf", "")

that was code i used to make it --->CSN
problem I have now is I trying something different with the filename ----> CSN-B.pdf
the -B part can change and someone could have a -1, or -2, or -3 and so on
so what would be code to try and remove the -(random variable).pdf ?
I think its farliy simple but I do not do well with the random variable stuff
Alan_G
That would be something like
!--c1-->
CODE
lngLen = Mid(f1.Name,1,InStr(f1.Name,"-") - 1)
fullyunknown
thanks so much
Alan_G
You're welcome sad.gif
fullyunknown
hate to ask another question.. but is there also code that let me delete everything from the - and to the left and the .pdf.
For example, i have CSN-B.pdf
wanna end up with just B
Alan_G
If it was always just one character, then
id("CSN-B.pdf",InStr("CSN-B.pdf","-") + 1,1)
would do it.
fullyunknown
so if it was to look like CSN.-10.pdf it wouldnt work? darn
Alan_G
What I posted wouldn't work - you'd need to change it to...........
!--c1-->
CODE
Mid("CSN.-10.pdf",InStr("CSN.-10.pdf","-") + 1,InStrRev("CSN.-10.pdf",".") - InStr("CSN.-10.pdf","-") - 1)
fullyunknown
now that code would work for files looking like CSN-B.pdf and CSN-10.pdf if so thank you so much for all your help on this issue
Alan_G
No problem - continued success with your project sad.gif
ncidentally, if you look in the VBA help files you'll find lots of info on Mid(), InStr() and InStrRev() and how they work.........
Alan_G
Just as a PS, I'd also assign the value of the InStr() and InStrRev() functions to a couple of varaibles.........
im intX As Integer, intY As Integer
Dim strNew As String
intX = InStr(StringToCheck,"-")
intY = InStrRev(StringToCheck,".")
strNew = Mid(StringToCheck, intX+ 1, intY- (intX- 1))
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.