-
dir help ?
Hi all
can anyone help with this.
I have a form with a drive list box on it
And i have a directory list box also.
What i'm looking for is when my form load the directory list box shows the path on the dir that i want the user to use.
I do not want them to be able to change the path.
Thanks for the help
-
So in the Change event reset it back to the inital directory.
-
You can set this via the Path function of the control :
Code:
Private Sub Form_Load()
Dir1.Path = "C:\My_Folder"
End Sub
However, I'm gonna get technical for once as there's so many things that can go wrong with this. :rolleyes:
Code:
Private Declare Function GetWindowsDirectory Lib _
"kernel32" Alias "GetWindowsDirectoryA" _
(ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Sub Form_Load()
Dim strWinDir As String, lngBuffer As Long
strWinDir = Space(255)
lngBuffer = GetWindowsDirectory(strWinDir, 255)
strWinDir = Left(strWinDir, lngBuffer)
If Len(Dir$(Left(strWinDir, 3) & "My_Folder")) <> 0 Then
Dir1.Path = Left(strWinDir, 3) & "My_Folder"
Else
MkDir Left(strWinDir, 3) & "My_Folder"
Dir1.Path = Left(strWinDir, 3) & "My_Folder"
End If
End Sub
Sorry this is a bit long, but it'll look for the windows directory, and return the drive this is on, so if my boot drive was D: rather than C: this would be picked up.
Also, if the My_Folder folder didn't exist, the above wouldn't crash like the top example, it will create thge folder, then set the directory boxes path to this. :)
Finally, so they won't be able to change the location, use the following after this code :
Code:
Dir1.enabled = false
-
Leave your dir box enabled, but in its change event put the directory in that you want them to be, i.e.[/Highlight]Dir1.Path = "c:\yourdir"[/Highlight]That way, they can click on this all day along and it is only going to take them right back to were you want them to be.