getting windows explorer to open a folder specified in a field entry (1 Viewer)

hillsee2

New member
Local time
Today, 21:25
Joined
Oct 4, 2005
Messages
9
Hiya, i work for an architectural company.

Within our database we have a project sheet, which gives alll the details regarding each of our jobs, from clients names, address to survey dates and when drawings are completed.

Each job we undertake we give a unique project ID, which is generated by the database. once the job is created we make a folder on our server and place all our CAD drawings in there.

what i would like to be able to do, is click on a button on the projectsheet form, which then uses the value of the project ID in the ProjectID field, and then use windows explorer to open that folder with the same projectID. is this possible?? ive managed to get a button to open a windows explorer window to our main jobs folder, but not to open the specified ProjectID folder.

Im sorry im totally new to all this stuff. so any help would be appreciated

thanx

keith
 

Oldsoftboss

AWF VIP
Local time
Tomorrow, 06:25
Joined
Oct 28, 2001
Messages
2,499
I think you would probably need to store the path in a table, rather than trying to run a windows search.

Dave
 

hillsee2

New member
Local time
Today, 21:25
Joined
Oct 4, 2005
Messages
9
Re

would that require me to manually add the folder location in to the table?

sorry im very new, bit of a noob ! :)
 

seth_belgium

WoW-Addict
Local time
Today, 22:25
Joined
Oct 4, 2005
Messages
175
If I understand you correctly, you have for example a project with ID abc123. This project-ID is stored in a field with the name txtProjectID.

All your project-folders are under the same path, for instance Z:\Projects

Then try this:

Dim ProjPath
ProjPath = "Z:\Projects\" & Me.txtProjectID.Value

Shell "C:\WINDOWS\explorer.exe """ & ProjPath & "", vbNormalFocus

The vbNormalFocus, you can change into vbMaximizedFocus if you want this.

Good luck!

Seth
 

hillsee2

New member
Local time
Today, 21:25
Joined
Oct 4, 2005
Messages
9
Cheers !!!!!!!

Wow great, thats works fab ! lol runs a dream.

cheers mate, thanx for all the help.

keith
 

ghudson

Registered User.
Local time
Today, 16:25
Joined
Jun 8, 2002
Messages
6,195
Do not forget to verify if the directory exists. For which it will error on the user if it does not.

Code:
    If Dir("C:\Test\DirX", vbDirectory) = "" Then
        CreateDirectory ("\\Server\Partition\Directory\Sub1\Sub2")
    End If
Also, how are you going to create the new directories since they will always be new and unique?
Code:
Private Sub Test()
    CreateDirectory ("\\Server\Partition\Directory\Sub1\Sub2")
End Sub
    
Public Sub CreateDirectory(sPath As String)
On Error GoTo DirectoryError
    
    Dim sPathPart As String
    Dim i As Integer
    
    If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
    
    For i = 1 To Len(sPath)
        If Mid(sPath, i, 1) = "\" Then
            sPathPart = Left(sPath, i - 1)
            MkDir sPathPart
        End If
    Next i
    
DirectoryError:
    Resume Next
    
End Sub
Check out my sample in this thread if you need to allow the user to browse and pick a file [or directory] or open a file from your db...Browse [Find a directory or file]
 

drb555

Registered User.
Local time
Today, 23:25
Joined
Jul 10, 2013
Messages
19
If I understand you correctly, you have for example a project with ID abc123. This project-ID is stored in a field with the name txtProjectID.

All your project-folders are under the same path, for instance Z:\Projects

Then try this:

Dim ProjPath
ProjPath = "Z:\Projects\" & Me.txtProjectID.Value

Shell "C:\WINDOWS\explorer.exe """ & ProjPath & "", vbNormalFocus

The vbNormalFocus, you can change into vbMaximizedFocus if you want this.

Good luck!

Seth
this may be a little late, but I use the shell command to open a directory, but I would like to check to see if the directory window is already open and if it is bring it to the foreground, if not then open a new directory window.

I do not seem to be able to find anyway to check if a directory window is open, any help would be much appreciated.

cheers in advance
D
 

drb555

Registered User.
Local time
Today, 23:25
Joined
Jul 10, 2013
Messages
19
Take a look at this article.
that's useful for finding running programs, but I am not sure how I would use it for finding an open directory window

for instance one of the open directory windows is

F:\Media\Television

I have tried substituting various names in the
Case "television": strClassName = "TELEVISION"

section but to no avail
 

JHB

Have been here a while
Local time
Today, 22:25
Joined
Jun 17, 2012
Messages
7,732
Ok - it should look for a certain directory, I thought it only should look if a program was open. Which MS-Windows version are you running?
 

drb555

Registered User.
Local time
Today, 23:25
Joined
Jul 10, 2013
Messages
19
Ok - it should look for a certain directory, I thought it only should look if a program was open. Which MS-Windows version are you running?
I am running windows 7 and windows XP although most work is done on the windows 7 machine
I have access 2000
 

drb555

Registered User.
Local time
Today, 23:25
Joined
Jul 10, 2013
Messages
19
ok I have discovered how to check to see if a explorer window is open, but I cannot work out how to bring the window to the foreground
Code:
[I]Dim OpenFold As Variant
Dim retval
    Dim oShell As Object
    Dim Wnd As Object
    Set oShell = CreateObject("Shell.Application")
    Dim dirx As Control
    Set dirx = "c:\testfolder"
        OpenFold = dirx
        strfolder = dirx
        Set oShell = CreateObject("Shell.Application")
        For Each Wnd In oShell.Windows
            If Wnd.Document.folder.Self.Path & "\" = OpenFold Then
                MsgBox "Folder is open"
                Exit Sub    ' Folder is open - exit this Sub
            Else
            End If
        Next Wnd
                 retval = Shell("C:\WINDOWS\explorer.exe """ & OpenFold, 1)[/I]

I need to find some code to replace the msgbox line that will bring the open folder to the foreground
 

DrallocD

Registered User.
Local time
Today, 16:25
Joined
Jul 16, 2012
Messages
112
google "SetForegroundWindow VBA" and you will see lots of examples.
 

drb555

Registered User.
Local time
Today, 23:25
Joined
Jul 10, 2013
Messages
19
google "SetForegroundWindow VBA" and you will see lots of examples.
thanks for that, I have worked out a way of doing it, but I will check it out

Code:
start:
Dim myform As Form
Set myform = Me
Dim pref As Form
Set pref = Forms!Preferences  'form where directory strings are kept
Dim wndx
       Dim dirz As Control
       Dim dirx As String
    Dim retval
    
    Dim OpenFold As Variant
    Dim oShell As Object
    Dim Wnd As Object

       Select Case dirs
        Case 1
        dirs = 0
        DoEvents
    Set dirz = pref!PVRdir

        Case 2
        dirs = 0
       DoEvents
    Set dirz = pref!TVdir


Case 3
        dirs = 0
        DoEvents
    Set dirz = pref!RadioDir

        End Select

           dirx = dirz

Dim x, y, z
dirx = Left(dirx, Len(dirx) - 1)
x = dirx
chk:
x = InStr(1, dirx, "\", vbTextCompare)


Do While x > 0
dirx = Mid(dirx, InStr(1, dirx, "\", vbTextCompare) + 1, Len(dirx))
 dirx = dirx
 x = InStr(1, dirx, "\", vbTextCompare)
Loop
Nextx:
wndx = dirx
        
     
     OpenFold = dirz
    strfolder = dirz

   Set oShell = CreateObject("Shell.Application")
        For Each Wnd In oShell.Windows
            If Wnd.Document.folder.Self.Path & "\" = OpenFold Then
             AppActivate wndx
       
                    Exit Sub    ' Folder is open - exit this Sub
            Else
            End If
        Next Wnd
                retval = Shell("C:\WINDOWS\explorer.exe """ & dirz, 1)
it seems to work fairly well and will cope with nested directories
 
Last edited:

Users who are viewing this thread

Top Bottom