INSERT INTO statement

a.phillips

Registered User.
Local time
Today, 12:06
Joined
Jul 19, 2011
Messages
37
dim filename as string
Dim strSQL As String

filename = Dir("Y:\Document_name\test.doc")

strSQL = "INSERT INTO tbl_filename (filename) VALUES ('filename')"
DoCmd.RunSQL strSQL

Hi, above is an example of the code I am having problems with, it is currently entering 'filename' into the table and I understand why, but how could I get it to insert 'test' into the table.

After this is working I am hoping for the code to filter through all of the files in this folder and store the name, size and date modified in a table. Does anyone have a document, or example code I could read on how to do the loop process.

Thanks for your help in advance.
 
dim filename as string
Dim strSQL As String

filename = Dir("Y:\Document_name\test.doc")

strSQL = "INSERT INTO tbl_filename (filename) VALUES ('filename')"
DoCmd.RunSQL strSQL

Hi, above is an example of the code I am having problems with, it is currently entering 'filename' into the table and I understand why, but how could I get it to insert 'test' into the table.

After this is working I am hoping for the code to filter through all of the files in this folder and store the name, size and date modified in a table. Does anyone have a document, or example code I could read on how to do the loop process.

Thanks for your help in advance.

It is currently entering the word 'filename' because that is what it is being told to do. In order to get the value of the variable filename into the SQL statement, you will need to break your SQL statement into pieces and then put the proper parts back together. Something like the following should work.

strSQL = "INSERT INTO tbl_filename (filename) VALUES ('" & filename & "')"
DoCmd.RunSQL strSQL
 
* In place of the Insert Into statement you need DoCmd.OutputTo.
* For looping through your files and saving the details into a table, have a look at this:
http://allenbrowne.com/ser-59alt.html
 
Thanks for the help this worked.

I'll have a read of that page now, thanks.
 

Users who are viewing this thread

Back
Top Bottom