By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,656 Members | 1,779 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,656 IT Pros & Developers. It's quick & easy.

Using FileDialog property to open and display FileName in a textbox and in a table

P: 2
I've found code in thread:
Using FileDialog property to open File and display FileName in a textbox
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
Jul 7 '09 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 635

To get you started the following code can be moded to your database to create a new directiory
Expand|Select|Wrap|Line Numbers
  1. Sub CreateDirectory()
  2.     Dim rs As New ADODB.Recordset
  3.     Dim SQL As String
  5.     SQL = "SELECT FName, SName, ID FROM tblContacts WHERE ID = 2"
  6.     rs.Open SQL, CurrentProject.Connection, adOpenStatic, adLockReadOnly
  8.     MkDir "C:\" & rs("FName") & " " & rs("SName") & " ID is " & rs("ID")
  10.     rs.Close
  11.     Set rs = Nothing
  12. End Sub
and to obtain a list of selected files in a gived directory some thing like this perhapse
Expand|Select|Wrap|Line Numbers
  1. Sub ListFiles()
  2.     Dim dlgOpen As FileDialog
  3.     Dim ThisFilePath As Variant
  4.     Dim FileName As String
  5.     Set dlgOpen = Application.FileDialog(msoFileDialogFilePicker)
  7.     With dlgOpen
  8.         .AllowMultiSelect = True
  9.         .Filters.Add "Excel Files", "*.xls", 1
  10.         If .Show = -1 Then
  11.             For Each ThisFilePath In .SelectedItems
  12.                 FileName = Mid(ThisFilePath, InStrRev(ThisFilePath, "\") + 1)
  13.                 MsgBox FileName
  14.             Next ThisFilePath
  15.         End If
  16.     End With
  17. 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

Jul 7 '09 #2

Expert 5K+
P: 8,684
Download the Attachment to see how to select a File from the File Dialog, then to display its Absolute Path in a Text Box.
Jul 7 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.