Problem with Dialog

G

Guest

I have dumped the Active X for the API Common Dialog. I want however the
result of the selection of the Dialog to be a variant. I can select the
files from the Dialog, but am unable to add them to my lstbox. Any help
would be great! Thanks!

Function LaunchCD(strform As Form) As Variant
Dim V As Variant
Dim OpenFile As OPENFILENAME
Dim lReturn As Long
Dim sFilter As String
OpenFile.lStructSize = Len(OpenFile)
OpenFile.hwndOwner = strform.Hwnd
sFilter = "Excel Files (*.xls)" & Chr(0) & "*.xls"
'"JPEG Files (*.JPG)" & Chr(0) & "*.JPG" & Chr(0)
OpenFile.lpstrFilter = sFilter
OpenFile.nFilterIndex = 1
OpenFile.lpstrFile = String(257, 0)
OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
OpenFile.lpstrFileTitle = OpenFile.lpstrFile
OpenFile.nMaxFileTitle = OpenFile.nMaxFile
OpenFile.lpstrInitialDir = "n:\trafmon\vc_data\newtube"
OpenFile.lpstrTitle = "Select a file using the Common Dialog DLL"
OpenFile.flags = cdlOFNAllowMultiselect Or cdlOFNExplorer
lReturn = GetOpenFileName(OpenFile)
If lReturn = 0 Then
MsgBox "A file was not selected!", vbInformation, _
"Select a file using the Common Dialog DLL"
Else
LaunchCD = Trim(Left(OpenFile.lpstrFile, InStr(1,
OpenFile.lpstrFile, vbNullChar) - 1))
End If

LaunchCD = V

End Function


Private Sub Command2_Click()

Dim I As Integer
Dim V As Variant
Dim Fname As String
Dim F

V = LaunchCD(Me)

If Not IsEmpty(V) Then
For I = 0 To UBound(V)
Fname = StrReverse(Split(StrReverse(V(I)), "\", 2)(0))

Debug.Print Fname
Text1.AddItem F
Debug.Print F
Next I

End If
End Sub
 
D

Douglas J Steele

Not sure I understand what you're asking.

What do you mean by "the result of the selection of the Dialog to be a
variant"?

Is your specific issue how to get the multiple files that have been
selected?

They're returned in lpstrFile as the path to the current directory followed
by the file names of the selected files, with each entry separated by Null
characters (chr(0)).There's an extra Null character after the last file
name.

That means you probably need:

Dim varFiles As Variant

If Not IsEmpty(V) Then
varFiles = Split(V, Chr$(0))
For I = 1 To UBound(varFiles)
Fname = StrReverse(Split(StrReverse(varFiles(I)), "\",
2)(0))
Debug.Print Fname
Text1.AddItem Fname
Debug.Print Fname
Next I
End If
 
G

Guest

I tried it, and it's still not working? Perhaps I haven't successfully built
the function correctly Douglas? Could it be that my function is wrong, and
that LaunchCD doesn't equal the Variant "V"?
 
G

Guest

Now I've modified a few things, but the Dialog only populates 1 file at a
time. When I try to select more than 1, I get something else in my lstbox
that is not the files names. Basically all I want, is a Dialog to give me
the option to select files, then from the files, strip down the names and
place them into a lstbox. I've done this countless times before, but when
trying to run the code from other peoples machines, it bombs, especially the
Active X control. To resolve this issue in another VBA program, I placed
Dialog controls on seperate Forms, and called them from there, but I couldn't
duplicate that in Access. I tried placing a Dialog on a seperate form, but
couldn't call it in my code. So I'm stuck!
 
D

Douglas J Steele

The problem would appear to be the line of code

LaunchCD = V

in your LaunchCD function.

Since you haven't defined a value for V anywhere in the function, you're
always going to be passing back a Null value.
 
D

Douglas J. Steele

Have you checked what's actually getting passed back by your LaunchCD
function?

BTW, you can change

StrReverse(Split(StrReverse(varFiles(I)), "\", 2)(0))

to

Dir(varFiles(i))
 

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

Similar Threads


Top