Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code to allow loading of multiple files

Status
Not open for further replies.

ri

Programmer
Nov 2, 2000
12
GB
I know this has something to do with GetNextPathName. Need to allow the user to select & load multiple files into a database via the application's File (menu) --> Open. Has anyone done anything similar before?
 
Hi

You can add a Common Dialog control to your form and then use the following code

Code:
   With CommonDialog1
      .Flags = cdlOFNAllowMultiselect
      .Filter = "*.*" 'change to your file type
      .ShowOpen

      MsgBox .FileName
   End With

You'll notice the filenames are separated by spaces.
You can then write a routine that parses that data into a more workable format like an array & off you go!

Have fun
caf
 
Just wondering if anyone knows of an existing routine/control, etc... that does this for you - the part about parsing the filename list - or do I need to write it myself?
 
There's an easy way to parse a string in VB6. Use the split function.

Dim sFiles() as string

sFiles = split(cdlFiles.FileName)

By default split will use the space char as the delimiter. So this should work for this case. Hope that helps.
 
Caf, I think you need to pipe that filter statement. I could be wrong, but I don't think you'll see any files!

ri, here's some code to play with - start a new project, and drop a CommonDialog onto a form. Also, when it splits the file names, the first array value is the path followed by each selection.


Option Explicit

Private Sub Form_Load()
Dim strFileNames() As String, intX As Integer, FileOpened As Boolean
With CommonDialog1
.Flags = cdlOFNAllowMultiselect
.Filter = "All Files (*.*)|*.*"
.ShowOpen
End With
strFileNames = Split(CommonDialog1.FileName)
For intX = 1 To UBound(strFileNames)
MsgBox strFileNames(0) & strFileNames(intX)
FileOpened = MyOpenFileRoutine(strFileNames(0) & strFileNames(intX))
If Not FileOpened Then MsgBox strFileNames(intX) & " failed to open!"
Next
End Sub

Function MyOpenFileRoutine(strFileName As String) As Boolean
MyOpenFileRoutine = False
'...
'Place your open routine here
'
' If <<all went well>> Then
MyOpenFileRoutine = True
' end if
End Function


HTH,

CB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top