isnoend2001
asked on
Add the last Directory File name from a path to a combobox
Typical Paths
C:\Documents and Settings\All Users.WINDOWS\Documents\Ro ofCalculat or\William s 1247 RiverBend rd\Roofing Bids
C:\Documents and Settings\All Users.WINDOWS\Documents\Ro ofCalculat or\William s 1247 RiverBend rd\Fencing Bids
C:\Documents and Settings\All Users.WINDOWS\Documents\Ro ofCalculat or\William s 1247 RiverBend rd\LanndScaping Bids
C:\Documents and Settings\All Users.WINDOWS\Documents\Ro ofCalculat or\William s 1247 RiverBend rd\Gardner Bids
C:\Documents and Settings\All Users.WINDOWS\Documents\Ro ofCalculat or\William s 1247 RiverBend rd\New Gutter Bids
Add to Combo box
With cboBids
.AddItem Roofing Bids
.AddItem Fencing Bids
.AddItem LanndScaping Bids
.AddItem Gardner Bids
.AddItem New Gutter Bids
End With
How to do this ?
C:\Documents and Settings\All Users.WINDOWS\Documents\Ro
C:\Documents and Settings\All Users.WINDOWS\Documents\Ro
C:\Documents and Settings\All Users.WINDOWS\Documents\Ro
C:\Documents and Settings\All Users.WINDOWS\Documents\Ro
C:\Documents and Settings\All Users.WINDOWS\Documents\Ro
Add to Combo box
With cboBids
.AddItem Roofing Bids
.AddItem Fencing Bids
.AddItem LanndScaping Bids
.AddItem Gardner Bids
.AddItem New Gutter Bids
End With
How to do this ?
ASKER
Thanks for your reply I have decided not to use the Dir function
My app creates the directories so i have decided to store the files/paths in an array and save the array.
i have tried this:
d Settings\All Users.WINDOWS\Documents\Ro ofCalculat or\William s 1247 RiverBend rd\New Gutter Bids
I only want to return: New Gutter Bids
what is wrong ?
My app creates the directories so i have decided to store the files/paths in an array and save the array.
i have tried this:
Private Sub Command5_Click()
Dim Result As String
Result = LastDirctory("C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Williams 1247 RiverBend rd\New Gutter Bids")
Debug.Print Result
End Sub
Function LastDirctory(FileWithPath As String) As String
Dim BackSlash As String
Dim position As Integer
BackSlash = "\"
position = InStrRev(FileWithPath, BackSlash, , vbTextCompare)
LastDirctory = Right(FileWithPath, position)
End Function
But this returns this:d Settings\All Users.WINDOWS\Documents\Ro
I only want to return: New Gutter Bids
what is wrong ?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for adding that
I get Bad Filename or number on this line:
MyName = Dir(MyPath, vbDirectory) 'Retrieve the first entry.
I get Bad Filename or number on this line:
MyName = Dir(MyPath, vbDirectory) 'Retrieve the first entry.
ASKER
I got this to work:
Function LastDirctory(FileWithPath As String) As String
Dim FilewithPathLength As Integer
Dim BackSlash As String
Dim position As Integer
FilewithPathLength = Len(FileWithPath)
BackSlash = "\"
position = InStrRev(FileWithPath, BackSlash, , vbTextCompare)
position = FilewithPathLength - position
LastDirctory = Right(FileWithPath, position)
End Function
Function LastDirctory(FileWithPath As String) As String
Dim FilewithPathLength As Integer
Dim BackSlash As String
Dim position As Integer
FilewithPathLength = Len(FileWithPath)
BackSlash = "\"
position = InStrRev(FileWithPath, BackSlash, , vbTextCompare)
position = FilewithPathLength - position
LastDirctory = Right(FileWithPath, position)
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
Or do you mean JUST the LAST directory, which is "New Gutter Bids" and discard the other?