Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / November 2007

Tip: Looking for answers? Try searching our database.

Using InStr Function to Parce a string

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lisab - 14 Nov 2007 21:12 GMT
In inStr function and using it has always caused me a headache.

I did the following to get the [personName] from the datafile path.  I would
like to know if there was an easier way to accomplish the same.  
------------------------------------------------------------
'Get the Person name from the file path
'example C:\ProjectName_ContractCode_\DatabaseName_PersonName.mdb

Dim CPos, LastPos, DPos, UPos, nameLength As Integer

'Get the position of the .dot
DPos = InStr(strPath, ".")

'There are several underscores in the path
'I know the name comes after the last underscore
'Get the position of the last underscore
CPos = InStr(strPath, "_")
   Do While CPos > 0
       LastPos = CPos
       CPos = InStr(CPos + 1, strPath, "_")
       
   Loop

'the length of the name is the distance between the last underscore and the
dot    
nameLength = DPos - LastPos - 1

strName = Right$(strPath, (nameLength + 4))
strName = Left$(strName, nameLength)
Ken Snell (MVP) - 14 Nov 2007 21:24 GMT
Perhaps this will be easier, based on the example that has underscore before
person's name:

Left(Mid(strPath, InStrRev(strPath, "_") + 1), Len(Mid(strPath,
InStrRev(strPath, "_") + 1)) - 4)

Signature

       Ken Snell
<MS ACCESS MVP>

> In inStr function and using it has always caused me a headache.
>
[quoted text clipped - 27 lines]
> strName = Right$(strPath, (nameLength + 4))
> strName = Left$(strName, nameLength)
Lisab - 14 Nov 2007 23:46 GMT
THANKS.

OMG, I have to be fresh and headach free in order to deal with mixing the
Left,Right, Mid, & InStr functions :)

InStrRev --> that a new one I didn't know about

Thanks again.

> Perhaps this will be easier, based on the example that has underscore before
> person's name:
[quoted text clipped - 33 lines]
> > strName = Right$(strPath, (nameLength + 4))
> > strName = Left$(strName, nameLength)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.