Solved Open a specific folder using the first x letters

dim

Registered User.
Local time
Today, 17:51
Joined
Jul 20, 2012
Messages
54
Hi,

I need to open from a form a specific folder where will match only the first 3 letters.
Example:
On the form I have a field named [CompanyName] and in this example [CompanyName]="ABC Customer"
On the server, the folder name for this Customer is only ABC (without Customer)
To open this folder I tried this, but doesn't work:

strFoldername = Left(Me.CompanyName, 3)
If Dir("\\datasrv\serverdata\Customer's Documents\PO\" & strFoldername, vbDirectory) = "" Then
MsgBox "Missing folder with this Company name"
Else
FollowHyperlink "\\datasrv\serverdata\Customer's Documents\PO\" & strFoldername & "*"
End If

Can you help please?

Thanks
 
Do you get an error or what does "Doesn't work" actually mean?
 
Presently, don't find any folder which start with ABC, so appear the message "Missing folder with this Company name"
 
Okay so try hard coding it in the immediate window: Type

? Dir("\\datasrv\serverdata\Customer's Documents\PO\ABC" , vbDirectory)

And see what it gives you.
Then try

? Dir("\\datasrv\serverdata\Customer's Documents\PO\ABC\" , vbDirectory)
 
I tried and I I get a runtime error 490 "Cannot open the specified file"

strFoldername = Left(Me.CompanyName, 3)
If Dir("\\datasrv\serverdata\Customer's Documents\PO\ABC\", vbDirectory) = "" Then
MsgBox "Missing folder with this Company name or rename it to match the exactlly full name"
Else
FollowHyperlink "\\datasrv\serverdata\Customer's Documents\PO\" & strFoldername & "*"
End If
 
Did you try in the immediate window - exactly the two things I typed.
They are different. One has a trailing slash one doesn't.
 
Are you looking to open a folder dialog and see/select the files that it lists?
 
Sorry, I don't understand. You mind to put this code:
? Dir("\\datasrv\serverdata\Customer's Documents\PO\ABC" , vbDirectory)
under the click event of my button?
I tried anyway, but the question mark (?) is not recognized by vba and will be converted to Print
Can you explain please?
 
In the immediate window (open the VBA editor and press ctrl + G together) type the two lines I suggested, then press enter after each one.

? Dir("\\datasrv\serverdata\Customer's Documents\PO\ABC" , vbDirectory)
? Dir("\\datasrv\serverdata\Customer's Documents\PO\ABC\" , vbDirectory)

What results do you get?
 
This is what I get:

? Dir("\\datasrv\serverdata\Customer's Documents\PO\ABC" , vbDirectory)
ABC
? Dir("\\datasrv\serverdata\Customer's Documents\PO\ABC\" , vbDirectory)
.
 
You do not use * just use
Code:
FollowHyperlink "\\datasrv\serverdata\Customer's Documents\PO\" & strFoldername
 
As @Gasman said just open the directory - I missed the * on the end.
That won't work.
 
Ok, so I tried as you said, but I get a runtime error 490 "Cannot open the specified file"

Private Sub Command361_Click()

strFoldername = Left(Me.CompanyName, 3)
FollowHyperlink "\\datasrv\serverdata\Customer's Documents\PO\" & strFoldername

End Sub
 
Well test what strFolderName is?
 
Use the immediate window to test the correct syntax
Simply type

FollowHyperlink "\\datasrv\serverdata\Customer's Documents\PO\ABC"

And hit return.
The immediate window can save you hours of messing around in code!
 
Use the immediate window to test the correct syntax
Simply type

FollowHyperlink "\\datasrv\serverdata\Customer's Documents\PO\ABC"

And hit return.
The immediate window can save you hours of messing around in code!
I just tested just that and it works fine.?

Code:
tt="DB"
FollowHyperlink "c:\temp\" & tt
providing of course the data is correct?
 
@Gasman Of course!

According to the OP's report of the Dir() command above it was returning something.

So maybe something else is up.
I'm not a fan of the directory naming with an apostrophe in it. ( \Customer's )
 
Nor I, but I just tried this
Code:
tt="DB"
FollowHyperlink "c:\temp\Customer's\" & tt
and that works fine as well? :)
 
Let's take another example:
If the name of the company is TERRA LAND and the folder name is TERRA, this code doesn't work:

strFoldername = Left(Me.CompanyName, 3)
FollowHyperlink "\\datasrv\serverdata\Customer's Documents\PO\" & strFoldername

If I use the first 5 letters of the entire word Terra is working, but I need to use only the first 3 letters (TER)
For this I tried too:

strFoldername = Left(Me.CompanyName, 3)
FollowHyperlink "\\datasrv\serverdata\Customer's Documents\PO\" & strFoldername & "*"

but doesn't work.

Any others idea?
 

Users who are viewing this thread

Back
Top Bottom