Directory dialogue box server path

BWG3

Registered User.
Local time
Today, 10:53
Joined
Sep 22, 2009
Messages
44
I have a module with the code below. When I click on my browse button, it open the generic directory dialogue box. I can not locate where in the code it is defining the path to open the directory dialogue box. Can anyone please help me find out what part of the code is generating the directory dialogue box so I can modify it to open to a specific server path, such as \\server123\Folder1\Folder2.

Option Compare Database
Option Explicit

Private Type BrowseInfo
hwndOwner As Long
pidlRoot As Long
sDisplayName As String
sTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
Private Declare Function SHBrowseForFolder Lib "shell32.dll" (bBrowse As BrowseInfo) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" (ByVal lItem As Long, ByVal sDir As String) As Long

' Let the user browse for a directory. Return the
' selected directory. Return an empty string if
' the user cancels.
Public Function BrowseForDirectory() As String
Dim browse_info As BrowseInfo
Dim item As Long
Dim dir_name As String
'modified for MS Access/VBA
With browse_info
' .hwndOwner = Application.hWndAccessApp
.pidlRoot = 0
.sDisplayName = Space$(260)
.sTitle = "Select Directory"
.ulFlags = 1 ' Return directory name.
.lpfn = 0
.lParam = 0
.iImage = 0
End With
item = SHBrowseForFolder(browse_info)

If item Then
dir_name = Space$(260)
If SHGetPathFromIDList(item, dir_name) Then
BrowseForDirectory = Left(dir_name, _
InStr(dir_name, Chr$(0)) - 1)
Else
BrowseForDirectory = ""
End If
End If
End Function

Thanks.
Brandon
 
Looks like a duplicate post to me of:

http://www.access-programmers.co.uk/forums/showthread.php?t=179994

Please don't post duplicates, even if it is worded slightly differently. If you find you put the post in the wrong category, notify the mods to move it for you (by clicking on the exclamation point inside the red triangle on the top right of the post).
 
Last edited:
Couldn't be bothered to read all of your code, but couldn't you try something the lines of:-
Code:
Sub YourCommandNameHere_Click()
ShellID = Shell("Explorer.exe DirectoryPathHere")
EndSub
 
Hi,

here is what i use. its pretty simple

Code:
Option Compare Database
Public strDatabaseName As String
Public strGetPath as String

Private Type OPENFILENAME
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    lpstrFilter As String
    lpstrCustomFilter As String
    nMaxCustFilter As Long
    nFilterIndex As Long
    lpstrFile As String
    nMaxFile As Long
    lpstrFileTitle As String
    nMaxFileTitle As Long
    lpstrInitialDir As String
    lpstrTitle As String
    Flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    lpstrDefExt As String
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
    End Type
    
    Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" _
    (pOpenfilename As OPENFILENAME) As Long

    'COLLECT PATH FILE
Function LaunchCD(strForm As Form) As String
    Dim OpenFile As OPENFILENAME
    Dim lReturn As Long
    Dim sFilter As String
    
    'On Error GoTo LaunchCD_Error
    
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim strFileRoot As String
    
    OpenFile.lStructSize = Len(OpenFile)
    OpenFile.hwndOwner = strForm.hwnd
    sFilter = "All Files (*.*)" & Chr(0) & "*.*" & Chr(0) & _
    "JPEG Files (*.JPG)" & Chr(0) & "*.JPG" & Chr(0)
    OpenFile.lpstrFilter = sFilter
    OpenFile.nFilterIndex = 1
    OpenFile.lpstrFile = String(150, 0)
    OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
    OpenFile.lpstrFileTitle = OpenFile.lpstrFile
    OpenFile.nMaxFileTitle = OpenFile.nMaxFile

    'Set up your startup folder HERE!!
    OpenFile.lpstrInitialDir = "C:\users\"

    'Add a title to your browse box HERE!!
    OpenFile.lpstrTitle = "My Custom Message"

    OpenFile.Flags = 0
    lReturn = GetOpenFileName(OpenFile)
    If lReturn = 0 Then
        MsgBox "A file was not selected!", vbInformation, _
        "My MessageBox Message"
        LaunchCD = strGetPath
    Else
        LaunchCD = Trim(Left(OpenFile.lpstrFile, InStr(1, OpenFile.lpstrFile, vbNullChar) - 1))
    End If
   
    On Error GoTo 0
    Exit Function

LaunchCD_Error:

    MsgBox "Error " & Err.Number & vbCrLf & _
    " (" & Err.Description & "). Please contact support for assistance", vbOKOnly, "My Error title"
End Function

to use it, i place this in my button_Click property

Code:
'this calls the browse box
strGetPath = LaunchCD(Me)

'this places the value return into a textbox
Me!MyPath.Value = strGetPath

HTH


Nidge
 
Thanks Nigel and dbDamo for posting in the duplicate post instead of posting in the original. If it is a duplicate (and my post said it was) you should not post here but instead go to the original thread so that we don't have things in more than one spot.

Doesn't anyone read the threads anymore?
 
Had you provided a link to the original thread bob, then maybe I would have posted there instead, but as you posted a link to this thread (yes, check it, you did) I couldn't really be bothered to go searching for the other thread.

Perhaps you should think before you post smart comments?
 
Had you provided a link to the original thread bob, then maybe I would have posted there instead, but as you posted a link to this thread (yes, check it, you did) I couldn't really be bothered to go searching for the other thread.

Perhaps you should think before you post smart comments?
And perhaps you would do as well. And, take some time smartso to look on the New Posts page as it would be there pretty close together.
 
How would I possibly know it was a duplicate post of a recent thread, did you state that? For all I know he could have posted the original question a week ago with no response so decided to post again.

I suggest in future you either provide a link to the correct thread or accept that the average user whois here to help is not going to search for the duplicate thread.
 
How would I possibly know it was a duplicate post of a recent thread, did you state that?
Yes,
boblarson said:
Looks like a duplicate post to me
I suggest in future you either provide a link to the correct thread or accept that the average user whois here to help is not going to search for the duplicate thread.
And if I were someone who just got a message saying that they shouldn't have done that, from someone with almost 9 years on the board and with over 16,000 posts, I would not have responded with venom, but instead just said, "sorry" and let it go. But, that was not the case, eh?

So, anyway, I am done with this now and for the time being have you on my ignore list.
 
You stated that it was a duplicate post, not a duplicate post of a recent thread and I'm sure someone as intelligent as yourself can see the difference....

I do not believe that 16,000 posts and 9 years on a forum give you the right to be rude to people who were given no alternative thread to post in. Had you said "sorry guys, I did say this was a duplicate thread so please don't post here", I would have apologised and informed you of your mistake. But you didn't, did you.
 
Hey Guys,

its only a duplicate post, not the end of the world as we know it:)

in fairness,

A. i saw the note from Bob and clicked the link which i believe did take me back the same place where i left my post ( maybe i was mistaken but it seemed to )

B.i dont read every single new post. if posts have the identical heading then sure i would expect a duplicate but if they are different, they very well could be different posts but like i said, i dont read all of the posts.

Bob is a long standing member of this forum and i believe deserves at least some respect without a sharp tongued response over a little bit of advice. He is also a part of the moderator team and has the right to reprimand if required, posters who duplicate or encourage duplicated posters by continuing the thread even after the point has been raised.

you may find in the future that you would be missing that crucial bit of advice that could so easily be provided by the very person you antagonise and therefore, go without which would be a shame.

remember, if there wasnt anyone here to keep the forum in line and organised, we would all be buying iphones by now and the place would be in a right mess!

i would suggest a perusal over the full thread and re read the comments from the start to establish whether or not the original intention was to be rude or to advise.

from my part, i will ensure that i take a little more notice in future and will not stray too far.....:eek:


best regards

Nigel
 
Last edited:
I do not have respect for someone because of the number of years they have been on a forum or because of the number of posts they have made, but I do respect bob for the amount he does help people on this forum.

I did however take offence to the sarcastic comment he made, which is why I replied in the way I did, which I did not feel was particularly rude, though bob probably feels the same way about his comment.
 
Nigel, DB, thank you for your replies. They helped.

To all, I apoligize for posting the duplicate post. I was just unsure of what I was supposed to do if I thought I could change the title to be more specific. I did not mean to cause all this animosity. Again, I apoligize and I thank you for all your help.
 

Users who are viewing this thread

Back
Top Bottom