Quote:
Originally Posted by sajtovi007
Hi,
I've found code in thread:
Using FileDialog property to open File and display FileName in a textbox
but:
1. I do not know how to add it in to ACCESS 2003 database.
2. I have fields in database with FirstName, LastName and IDnumber. How to Create folder named "LastName FirstName IDnumber" from ACCESS 2003 (on a click on a batton)?
3. And, additionaly, is it possible to add all files from this folder (folder created and opened in previous step) on a list on the form (or as labels-hyperlinks on current form)?
Thanks in advance
Hi
To get you started the following code can be moded to your database to create a new directiory
- Sub CreateDirectory()
-
Dim rs As New ADODB.Recordset
-
Dim SQL As String
-
-
SQL = "SELECT FName, SName, ID FROM tblContacts WHERE ID = 2"
-
rs.Open SQL, CurrentProject.Connection, adOpenStatic, adLockReadOnly
-
-
MkDir "C:\" & rs("FName") & " " & rs("SName") & " ID is " & rs("ID")
-
-
rs.Close
-
Set rs = Nothing
-
End Sub
and to obtain a list of selected files in a gived directory some thing like this perhapse
- Sub ListFiles()
-
Dim dlgOpen As FileDialog
-
Dim ThisFilePath As Variant
-
Dim FileName As String
-
Set dlgOpen = Application.FileDialog(msoFileDialogFilePicker)
-
-
With dlgOpen
-
.AllowMultiSelect = True
-
.Filters.Add "Excel Files", "*.xls", 1
-
If .Show = -1 Then
-
For Each ThisFilePath In .SelectedItems
-
FileName = Mid(ThisFilePath, InStrRev(ThisFilePath, "\") + 1)
-
MsgBox FileName
-
Next ThisFilePath
-
End If
-
End With
-
End Sub
This assumes you want to select the directory manualy (if not i don't know how you will now wich directories exist). A plausible alternative is to use the DIR function (see Access help or post back if you need a pointer or two on that).
There is another alternative using the FileSystemObject (this will need a reference to the 'Microsoft Scripting Runtime' Library) but that is even more stuff to learn, not a bad think, but you can't learn it ALL at once!!.
Hope this helps
MTB