I'm using Access 2000. I've built a simple form that uses the common dialog to build a text string of selected files that I'll load as new records into one of the tables. I want to allow for multiple files to be selected so I've set the .FLAG property to allow multiple-selections (.FLAG = cdlOFNAllowMultiselect). I'm trying to use an array that traps the various parts of the directory and file names returned by the common dialog, but not having any luck putting them back together. If I select two files then I'd like to have a two-dimension array with the full directory and file name for each.
Thanks alot for any help!
Thanks alot for any help!
Code:
Private Sub Command12_Click()
Dim fileflags As FileOpenConstants
Dim filefilter As String
Dim I As Integer
Dim Y As Integer
Dim Z As Integer
Dim FileNames$()
Dim int1 As Integer
Dim str2 As String
'clear the form fields
lblPreview.Caption = ""
lblText1.Caption = ""
lblText2.Caption = ""
int1 = intJobID
'Set the text in the dialog title bar
cdlg1.DialogTitle = "Open"
'Set the default file name and filter
With cdlg1
.InitDir = "D:\Temp"
.filename = ""
filefilter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
.Filter = filefilter
.FilterIndex = 0
.Flags = cdlOFNAllowMultiselect
End With
'Verify that the file exists
'fileflags = cdlOFNFileMustExist
'cdlg1.Flags = fileflags
'Show the Open common dialog box
cdlg1.ShowOpen
'Return the path and file name selected or
'Return an empty string if the user cancels the dialog
str1 = cdlg1.filename
'MsgBox "Length of the string is " & Len(str1)
Me.lblPreview.Caption = str1
cdlg1.filename = cdlg1.filename & Chr(32)
str5 = cdlg1.filename
Z = 1
For I = 1 To Len(cdlg1.filename)
I = InStr(Z, cdlg1.filename, Chr(32))
If I = 0 Then Exit For
ReDim Preserve FileNames(Y)
FileNames(Y) = Mid(cdlg1.filename, Z, I - Z)
Z = I + 1
Y = Y + 1
Next
If Y = 1 Then
lblText1.Caption = FileNames(0)
DoCmd.SetWarnings False
DoCmd.RunSQL "INSERT INTO tblFigures (job_ID,path) VALUES (" & int1 & ",'" & FileNames(0) & "');"
Me.Refresh
Else
lblText2.Caption = ""
For I = 0 To Y - 1
If I = 0 Then
lblText1.Caption = FileNames(0) & "\" & FileNames(I)
DoCmd.SetWarnings False
DoCmd.RunSQL "INSERT INTO tblFigures (job_ID,path) VALUES (" & int1 & ",'" & FileNames(0) & "\" & FileNames(1) & "');"
Me.Refresh
Else
DoCmd.SetWarnings False
lblText2.Caption = lblText2.Caption & UCase(FileNames(0) & "\" & FileNames(I)) & Chr$(13) & Chr$(10)
DoCmd.RunSQL "INSERT INTO tblFigures (job_ID,path) VALUES (" & int1 & ",'" & FileNames(0) & "\" & FileNames(I) & "');"
Me.Refresh
End If
Next
End If
End Sub