SQL Loop Question

frustrating

Registered User.
Local time
Today, 13:47
Joined
Oct 18, 2012
Messages
68
Hello.

I am trying to insert the file names of a specific directory into a table. Here is my code:
Code:
Private Sub Command0_Click()
'DoCmd.SetWarnings False
Dim folderpath As String
Dim strsql As String
folderpath = Dir("C:\blah\blahblah\test\*.*")
strsql = "INSERT INTO imported (FilePathName) Values (" & Chr(39) & folderpath & Chr(39) & ");"
Do While folderpath <> ""
CurrentDb.Execute (strsql)
'MsgBox folderpath
folderpath = Dir()
Loop
End Sub

My question is: When I print or msgbox the variable "folderpath", it iterates through the entire folder perfectly, yet when I do this SQL statement in the same loop, the variable does not change and just prints the first one x amount of times, where x is the amount of files in the directory. What am I doing wrong?

Thank you for any help.
 
DOH! I had to put my strsql declaration inside the loop so it would change.

Works fine now.
 

Users who are viewing this thread

Back
Top Bottom