Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Newbie
 
Join Date: Jul 2009
Posts: 2
#1: Jul 7 '09
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

Expert
 
Join Date: Jun 2007
Location: Derbyshire, UK
Posts: 369
#2: Jul 7 '09

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


Quote:

Originally Posted by sajtovi007 View Post

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
Expand|Select|Wrap|Line Numbers
  1. Sub CreateDirectory()
  2.     Dim rs As New ADODB.Recordset
  3.     Dim SQL As String
  4.  
  5.     SQL = "SELECT FName, SName, ID FROM tblContacts WHERE ID = 2"
  6.     rs.Open SQL, CurrentProject.Connection, adOpenStatic, adLockReadOnly
  7.  
  8.     MkDir "C:\" & rs("FName") & " " & rs("SName") & " ID is " & rs("ID")
  9.  
  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)
  6.  
  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


MTB
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,429
#3: Jul 7 '09

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


Quote:

Originally Posted by sajtovi007 View Post

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

Download the Attachment to see how to select a File from the File Dialog, then to display its Absolute Path in a Text Box.
Reply

Tags
access 2003, create folder in access, fielddialog, list of files in access, open file in access