Robert88
Robbie
- Local time
- Today, 21:40
- Joined
- Dec 18, 2004
- Messages
- 335
Hi All,
I am hoping soemone can help me?
I have code which will allow me to access files and folders form a folder with various files and folders within it @ "C:\CD Data", eventually I will change the path to read a CD but temporarily the information is on my hard disk. The code below sends it to message boxes based on what it has found within the folder;
I have also found an SQL statement which allows me to add data to a table;
I am wondering if the two can be merged together in order to place the data from the files and folderpath's can be imported into the table tblFilename with one field fldFieldname? The table only has one field.
I have tried;
With no success, syntax error on red above......
I got the idea from a microsoft example;
This example creates a new record in the Employees table.
But maybe this is better in the module rather than the CmdSearch button
If anybody can help, I would appreciate it.
Robert88
I am hoping soemone can help me?
I have code which will allow me to access files and folders form a folder with various files and folders within it @ "C:\CD Data", eventually I will change the path to read a CD but temporarily the information is on my hard disk. The code below sends it to message boxes based on what it has found within the folder;
Code:
Private Sub [B]CmdSearch[/B]_Click()
Set fs = Application.FileSearch
With fs
.LookIn = "C:\CD Data"
.FileName = "*.*"
.SearchSubFolders = True
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For I = 1 To .FoundFiles.Count
MsgBox [B].FoundFiles(I)[/B]
Next I
Else
MsgBox "There were no files found."
End If
End With
End Sub
I have also found an SQL statement which allows me to add data to a table;
Code:
INSERT INTO tblFilename (fldFieldname)
Values ('[B][Variable FoundFiles(I) from above][/B]');
I am wondering if the two can be merged together in order to place the data from the files and folderpath's can be imported into the table tblFilename with one field fldFieldname? The table only has one field.
I have tried;
Code:
Private Sub [B]CmdSearch[/B]_Click()
Dim dbs As Database
Set dbs = OpenDatabase("C:\CD Labeller - Microsoft Access 2003\CDlabel.mdb")
Set fs = Application.FileSearch
With fs
.LookIn = "C:\CD Data"
.FileName = "*.*"
.SearchSubFolders = True
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For I = 1 To .FoundFiles.Count
MsgBox .FoundFiles(I)
[COLOR="Red"]dbs.Execute " INSERT INTO tblFilename "_
& "(fldfieldname) Values "_
& "('.FoundFile(I)');"[/COLOR]
dbs.Close
Next I
Else
MsgBox "There were no files found."
End If
End With
End Sub
With no success, syntax error on red above......
I got the idea from a microsoft example;
This example creates a new record in the Employees table.
Code:
Sub InsertIntoX2()
Dim dbs As Database
' Modify this line to include the path to Northwind
' on your computer.
Set dbs = OpenDatabase("Northwind.mdb")
' Create a new record in the Employees table. The
' first name is Harry, the last name is Washington,
' and the job title is Trainee.
dbs.Execute " INSERT INTO Employees " _
& "(FirstName,LastName, Title) VALUES " _
& "('Harry', 'Washington', 'Trainee');"
dbs.Close
End Sub
But maybe this is better in the module rather than the CmdSearch button
If anybody can help, I would appreciate it.
Robert88
Last edited: