Article ID: 155980
Article Last Modified on 1/19/2007
{Path}<NULL>{File1.EXT}<NULL>{File2.EXT}<NULL>...{FileN.EXT}
For example, choosing the files Northwind.mdb, Solutions.mdb, and
Orders.mdb from the C:\MSOffice\Access\Samples folder results in:
C:\MSOffice\Access\Samples Northwind.mdb Solutions.mdb Orders.mdbIf the Common Dialog control only allows short file names to be selected, the path and file names are returned in a space delimited format,with the path listed first, and the files listed subsequently as follows:
{Path}<Space>{File1.EXT}<SPACE>{File2.EXT}<SPACE>...{FileN.EXT}
To determine the path and file name of each selected file, follow these
steps:
Table: SelectedFiles
--------------------
Field Name: FileName
Data Type: Text
Field Size: 255
Indexed: No
Form: FileList
--------------
Command button:
Name: Command0
Caption: Select Files
OnClick: [Event Procedure]
List box:
Name: FileList
RowSource: SelectedFiles
Option Compare Database
Option Explicit
Private Sub Command0_Click()
Dim MyString As String
Dim Path As String
Dim FileName As String
Dim I As Integer, J As Integer
Dim s As String
ReDim filearray(1) As String
'=============================================================
' LONG FILE NAME USAGE
'
' Use the following two lines of code for LONG file names only.
' If you will be using long file names, please unremark the
' following two lines and remark out the two lines under the
' Short File Name Usage section below.
'
Me!CmnDlg.flags = cdlOFNAllowMultiselect _
+ cdlOFNFileMustExist + cdlOFNHideReadOnly + _
cdlOFNNoDereferenceLinks + cdlOFNLongNames + cdlOFNExplorer
s = Chr(0)
'=============================================================
' SHORT FILE NAME USAGE
' Use the following two lines of code for SHORT file names only.
' If you will be using short file names, please unremark the
' following two lines and remark out the two lines under the
' Long File Name Usage section above.
'
' Me!CmnDlg.flags = cdlOFNAllowMultiselect _
+ cdlOFNFileMustExist + cdlOFNHideReadOnly
' s = Chr(32)
'==============================================================
Me!CmnDlg.DialogTitle = "Select 1 or More Files"
Me!CmnDlg.Filter = "All Files(*.*)|*.*|"
Me!CmnDlg.FileName = ""
Me!CmnDlg.CancelError = True
On Error GoTo SampleFiles_Err
Me!CmnDlg.MaxFileSize = 1024
Me!CmnDlg.ShowOpen
MyString = Me!CmnDlg.FileName
If InStr(1, MyString, s) > 0 Then
If (InStr(MyString, "\") + 1) = InStr(MyString, s) Then
Path = Trim(Left$(MyString, InStr(1, MyString, s) - 1))
Else
Path = Trim(Left$(MyString, InStr(1, MyString, s) - 1))_
& "\"
End If
FileName = Right$(MyString, Len(MyString) _
- InStr(1, MyString, s))
MyString = FileName
J = 0
For I = 1 To Len(FileName)
If Mid$(FileName, I, 1) = s Then
J = J + 1
End If
Next
J = J + 1
ReDim filearray(1 To J) As String
For I = 1 To UBound(filearray)
If I < UBound(filearray) Then
FileName = Trim(Left$(MyString, InStr(1, MyString, _
s) - 1))
MyString = Trim(Right$(MyString, Len(MyString) _
- InStr(1, MyString, s)))
Else
FileName = MyString
End If
filearray(I) = FileName
Next
Else
For I = 1 To Len(MyString)
If Mid$(MyString, I, 1) = "\" Then
Path = Left$(MyString, I)
FileName = Right$(MyString, Len(MyString) - I)
End If
Next
filearray(UBound(filearray)) = FileName
End If
DBEngine.Workspaces(0).BeginTrans
For I = 1 To UBound(filearray)
CurrentDb.Execute "INSERT INTO SelectedFiles(FileName)" _
& " VALUES ('" & Path & filearray(I) & "');"
Next
DBEngine.Workspaces(0).CommitTrans
ReDim filearray(1) As String
Me!FileList.Requery
SampleFiles_Exit_Sub:
Exit Sub
SampleFiles_Err:
If Err.Number <> cdlcancel Then MsgBox Err.Description
Resume SampleFiles_Exit_Sub
End Sub
Keywords: kbinfo kbinterop kbprogramming KB155980