Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extract database name from path string

Status
Not open for further replies.

brightstar

Technical User
Sep 20, 2002
233
anyone know how i can extract just the name of a database from its full path in a query?
i have the full path in a field, but i would also like another field to just hold the name of the database. there's over 300 records so i would rather not do it by hand!

cheers

free, anonymous advice provided by the whole world
 
Post an example of one the data in the field and I can do this for you.

Bob Scriver
Want the best answers? See FAQ181-2886
Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???

 
This will extract everything to the right of the last "\" in a path name:

Right(YourFullPathField,Len(YourFullPathField)-InStrRev(YourFullPathField,"\"))

-Gary
 
Copy and paste the following Function into a database module.
Public Function InStrRight(vSearchStr As String, vTargetStr As String, vStart As Long) As Long
Dim I As Integer
For I = vStart To 1 Step -1
If InStr(I, vSearchStr, vTargetStr, 1) = I Then
InStrRight = I 'Position of vTargetStr
Exit For
End If
Next I
End Function

Here is code for an Update query to strip off the database name and update a field.

UPDATE tblYourTableName as A SET A.DB = Mid$([PathToDB],InStrRight([PathToDB],"\",Len([PathToDB]))+1);

Update the SQL with the appropriate table name and field name for the path information.

Post back with questions or concerns.



Bob Scriver
Want the best answers? See FAQ181-2886
Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???

 
Brightstar: glalsop's code uses the built in function InStrRev which is not available in A97. I am still using A97 and had to write my own function to do the same thing. Both will work fine.

Bob Scriver
Want the best answers? See FAQ181-2886
Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top