473,387 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Browse for a folder

I need to let my users Browse to a Folder, not to a specific file
I am trying Terry Kreft's function below.

In the Declaration Section:
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias _
"SHGetPathFromIDListA" (ByVal pidl As Long, _
ByVal pszPath As String) As Long

Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias _
"SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) _
As Long

Private Const BIF_RETURNONLYFSDIRS = &H1

In the Code:
Public Function BrowseFolder(szDialogTitle As String) As String

Dim X As Long, bi As BROWSEINFO, dwIList As Long
Dim wPos As Integer

With bi
.hOwner = hWndAccessApp
.lpszTitle = szDialogTitle
.ulFlags = BIF_RETURNONLYFSDIRS
End With

dwIList = SHBrowseForFolder(bi)
szPath = Space$(512)
X = SHGetPathFromIDList(ByVal dwIList, ByVal szPath)

If X Then
wPos = InStr(szPath, Chr(0))
BrowseFolder = Left$(szPath, wPos - 1) <---- FAILS HERE
Else
BrowseFolder = vbNullString
End If

End Function
It always fails when trying to assign the result to the Function Name
At that time X = 1, wpos = 0, dwList = 145182352, and szPath has 512
blanks
It appears that nothing was returned from SHGetPathFromIDList
The error message is: Invalid procedure call or argument, because wpos
is 0

Thanks,
Hank Reed

Jun 5 '06 #1
3 2396
I forgot to say Access 2000 - sorry its Monday (No excuse)
Hank

Jun 5 '06 #2
"Hank" <ha********@aol.com> wrote:
I need to let my users Browse to a Folder, not to a specific file
I am trying Terry Kreft's function below.

In the Declaration Section:
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias _
"SHGetPathFromIDListA" (ByVal pidl As Long, _
ByVal pszPath As String) As Long

Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias _
"SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) _
As Long

Private Const BIF_RETURNONLYFSDIRS = &H1

In the Code:
Public Function BrowseFolder(szDialogTitle As String) As String

Dim X As Long, bi As BROWSEINFO, dwIList As Long
Dim wPos As Integer

With bi
.hOwner = hWndAccessApp
.lpszTitle = szDialogTitle
.ulFlags = BIF_RETURNONLYFSDIRS
End With

dwIList = SHBrowseForFolder(bi)
szPath = Space$(512)
X = SHGetPathFromIDList(ByVal dwIList, ByVal szPath)

If X Then
wPos = InStr(szPath, Chr(0))
BrowseFolder = Left$(szPath, wPos - 1) <---- FAILS HERE
Else
BrowseFolder = vbNullString
End If

End Function
It always fails when trying to assign the result to the Function Name
At that time X = 1, wpos = 0, dwList = 145182352, and szPath has 512
blanks
It appears that nothing was returned from SHGetPathFromIDList
The error message is: Invalid procedure call or argument, because wpos
is 0

Thanks,
Hank Reed


The variable szPath is not declared, thus it is implicitely declared
as variant, and then you get this error. Just put

Dim szPath As String

into your functtion, then it will work.

And *always* put

Option Explicit

at the top of the module!

HH
Matthias Kläy
--
www.kcc.ch
Jun 5 '06 #3
Matthias

I can't belive I missed that. I always Dim everything.
Although I would have thought that the default Variant would have
worked.

Thanks a bunch,
Hank Reed

Matthias Klaey wrote:
"Hank" <ha********@aol.com> wrote:
I need to let my users Browse to a Folder, not to a specific file
I am trying Terry Kreft's function below.

In the Declaration Section:
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias _
"SHGetPathFromIDListA" (ByVal pidl As Long, _
ByVal pszPath As String) As Long

Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias _
"SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) _
As Long

Private Const BIF_RETURNONLYFSDIRS = &H1

In the Code:
Public Function BrowseFolder(szDialogTitle As String) As String

Dim X As Long, bi As BROWSEINFO, dwIList As Long
Dim wPos As Integer

With bi
.hOwner = hWndAccessApp
.lpszTitle = szDialogTitle
.ulFlags = BIF_RETURNONLYFSDIRS
End With

dwIList = SHBrowseForFolder(bi)
szPath = Space$(512)
X = SHGetPathFromIDList(ByVal dwIList, ByVal szPath)

If X Then
wPos = InStr(szPath, Chr(0))
BrowseFolder = Left$(szPath, wPos - 1) <---- FAILS HERE
Else
BrowseFolder = vbNullString
End If

End Function
It always fails when trying to assign the result to the Function Name
At that time X = 1, wpos = 0, dwList = 145182352, and szPath has 512
blanks
It appears that nothing was returned from SHGetPathFromIDList
The error message is: Invalid procedure call or argument, because wpos
is 0

Thanks,
Hank Reed


The variable szPath is not declared, thus it is implicitely declared
as variant, and then you get this error. Just put

Dim szPath As String

into your functtion, then it will work.

And *always* put

Option Explicit

at the top of the module!

HH
Matthias Kläy
--
www.kcc.ch


Jun 5 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: mscir | last post by:
I just installed ASP after a couple of years of not using it, PWS Win 98 SE. A couple of things are throwing me, and I can't remember whether these worked in the past. One is I can't...
21
by: strutsng | last post by:
<input type="file"> only allows the user to browse for files. How about "browse for folder" dialog? Can html/javascript do that? I couldn't find any syntax for that. If not, please advise what...
5
by: deko | last post by:
I'm using the below code to allow users to browse for and select a folder. After selecting a folder from the dialog, the full path is returned to a text box and saved. The next time the user...
5
by: Eric Twietmeyer | last post by:
Hi, Does anyone know why starting with VS.NET 2002 (and same with 2003) it is no longer possible to browse to a directory that has "ept" as part of the path? It worked fine in Vc 6.x. My...
1
by: Ratan | last post by:
Can anybody tell me how to browse folder in ASP.Net, I know there is control for File browse but my requirement is to browse the folder and then just loop through files in that folder and upload...
4
by: Larry Brindise | last post by:
I have an asp.net application. I have used VStudio Web Deployment Project to create the MSI file. I copy the MSI file from my developer PC to my test server running Win2003Server Web Edition. I...
5
by: Dan | last post by:
I am working on a C# ASP.NET project where I need to allow the user to browse to a folder. The only way I see how to do this is use <input type=file>. But this makes the user select a file and...
5
by: Mike Moore | last post by:
I need to create something very similiar to the browse folder capability. This would allow me to support the following - A user would create a document on their server, then they would need to...
3
by: Highlander | last post by:
Hello all. Consider the following HTA: <HTML> <HEAD> <TITLE></TITLE></HEAD> <BODY> <SCRIPT LANGUAGE="VBScript"> Sub ButBrowse_onclick() '-- show browse window and Get file path:
6
by: Kuldeep | last post by:
Framework: Visual Studio 2005 Technology: ASP.NET 2.0 Language: C#.NET 2.0 I am trying to browse folders through the following piece of code. Please let me know if there is any kind of setting...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.