tags:

views:

67

answers:

2

i would like to use this syntax to update a table in access based on data from a txtfile.

fenton in his comments on this answer: http://stackoverflow.com/questions/2992168/read-text-file-line-by-line-and-insert-update-values-in-table/2992337#2992337

said that this is possible and i would like to see the exact syntax please

+3  A: 

There are a number of examples in Stackoverflow, eg http://stackoverflow.com/questions/327658/slow-msaccess-disk-writing/327773#327773

strSQL="INSERT INTO tableX ( Name1,Name2 ) " _
& "SELECT Name1,Name2 " _
& "FROM [ltd.txt] IN '' [Text;Database=c:\docs\;HDR=YES;]"

You can also refer to a file by using the connection string that would be used in a linked table:

strSQL = "SELECT SomeField " _
& "FROM [Text;HDR=YES;FMT=Delimited;IMEX=2;DATABASE=C:\SomeDir\].MyTextFile.csv" 
Remou
remou how come you never ask any questions? is it an ego thing?
I__
I do a lot of research.
Remou
so is it an ego thing?
I__
I for one don't ask questions on SO because the quality of answer is so low. The questions I need answered are much better asked in forums frequented by experienced professional Access developers. Most of the people on SO don't know a goddamned thing that is useful about Access as a development platform. They don't even know the difference between Access and Jet/ACE.
David-W-Fenton
+1 for fenton cause he's the man!
I__
btw fenton not true i get really good answers
I__
remou and handsup know a lot, also you are d fenton why would u have questions about access at all?
I__
I have questions about Access all the time, but they are usually complex enough to not get good answers on SO. The people on SO who can answer the kind of questions I have are reading in the other more sophisticated Access-specific forums where I post, and I also then get the help from all the other experienced Access developers there. The participants on SO tend not to know much about Access as development tool, which is where I most often encounter issues that I need help with.
David-W-Fenton
+1  A: 
Open "TESTFILE.TXT" For Input As #1 ' Open file.
Do While Not EOF(1) ' Loop until end of file.
  Line Input #1, TextLine ' Read line into variable.
  'Parse string into individual fields
  'Execute insert/update SQL statement
Loop
Close #1 ' Close file. 
BenV
This doesn't answer the question -- it's an entirely different solution.
David-W-Fenton
+1 for fenton cause he's the man!
I__