Need macro button to view a directory with windows explorer

A

Antonio-F100

Hello,

I need help creating the code for a macro
button on a form that will open a file
directory with windows explorer.


I have about 500 directories with very
long names and only want to input part
of the directory name into the table
that the form uses.


directory name examples:
c:\data\MK-0001_machine_tool_programs\
c:\data\MK-0002_machine_tool_fixtures\
c:\data\MK-0500_machine_tool_maintenance\


The first part of the dirctory name is always the same:
c:\data\


I just want to enter the next seven characters in my table
into a filed called "directory". Example:
Mk-0001
MK-0002
MK-0500


The rest of the directory name ideally can be represented by a
wildcard "*'. If this isn't possible, I can enter the whole
directory name into the table.


Therefore, when I open my form, select a record, then hit
the macro buttom, it will open windows explorer based on
the value stored in my "directory" field.


Thank you for your help.
Antonio
 
A

Allen Browne

You can open the Windows Explorer with FollowHyperlink and a string that
represents the folder name, e.g.:
FollowHyperlink "c:\data\MK-0001_machine_tool_programs\"

You can concatenate parts of that string together, e.g.:
Const strcTopPath = "c:\data\"
FollowHyperlink strcTopPath & "MK-0001_machine_tool_programs\"

You can use Dir() with a wildcard to get the first matching directory name,
e.g.:
Const strcTopPath = "c:\data\"
Dim strFolder As String
strFolder = Dir$(strcTopPath & [SomeField] & "*", vbDirectory)
If strFolder <> vbNullString Then
FollowHyperlink strcTopPath & strFolder
End If

An alternative to FollowHyperlink is to shell the Windows Explorer.
This also lets you use its command line switches, e.g.:
Call Shell (Environ("windir") & "\explorer.exe /e, /select, """ & _
strcTopPath & strFolder & """", vbNormalFocus)
 
A

Antonio-F100

Thank you Allen, I will give it a try and let you know how I make out.
Antonio


Allen said:
You can open the Windows Explorer with FollowHyperlink and a string that
represents the folder name, e.g.:
FollowHyperlink "c:\data\MK-0001_machine_tool_programs\"

You can concatenate parts of that string together, e.g.:
Const strcTopPath = "c:\data\"
FollowHyperlink strcTopPath & "MK-0001_machine_tool_programs\"

You can use Dir() with a wildcard to get the first matching directory name,
e.g.:
Const strcTopPath = "c:\data\"
Dim strFolder As String
strFolder = Dir$(strcTopPath & [SomeField] & "*", vbDirectory)
If strFolder <> vbNullString Then
FollowHyperlink strcTopPath & strFolder
End If

An alternative to FollowHyperlink is to shell the Windows Explorer.
This also lets you use its command line switches, e.g.:
Call Shell (Environ("windir") & "\explorer.exe /e, /select, """ & _
strcTopPath & strFolder & """", vbNormalFocus)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Antonio-F100 said:
Hello,

I need help creating the code for a macro
button on a form that will open a file
directory with windows explorer.


I have about 500 directories with very
long names and only want to input part
of the directory name into the table
that the form uses.


directory name examples:
c:\data\MK-0001_machine_tool_programs\
c:\data\MK-0002_machine_tool_fixtures\
c:\data\MK-0500_machine_tool_maintenance\


The first part of the dirctory name is always the same:
c:\data\


I just want to enter the next seven characters in my table
into a filed called "directory". Example:
Mk-0001
MK-0002
MK-0500


The rest of the directory name ideally can be represented by a
wildcard "*'. If this isn't possible, I can enter the whole
directory name into the table.


Therefore, when I open my form, select a record, then hit
the macro buttom, it will open windows explorer based on
the value stored in my "directory" field.


Thank you for your help.
Antonio
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top