I want to upload a text file to a access database, but the string does not work. I guess the problem is with the quote marks or something of the sort.

The string is as follows:

rs.Open "SELECT * FROM [" & Me.Text1.Text & "] ", objConnection, adOpenStatic, adLockOptimistic, adCmdText

Text1.text is contains the name of the file to be put into the database.


6 Years
Discussion Span
Last Post by vb5prgrmr

Its little confusing. Is Text1 a Text box or Text file which id usually saved as .txt file? Secondly your SELECT statement is not correct.



The correct way would be as follow -

Dim strMyTableName As String

strMyTableName = Text1.Text 'Or if you get the string from another form..
'strMyTableName = frm...Text1.Text

 rs.Open "SELECT * FROM " & strMyTableName & "", objConnection, adOpenStatic, adLockOptimistic, adCmdText 'Only use the "[]" if your table name has spaces between them, as in - My Table Name

I hope this solves your problem.


Kinwang, Andre,...

>Text1.text is contains the name of the file to be put into the database.

Mr. Nervous is trying the insert the contents of a text file into the database, but as you can see from his select statement, and if you think about the logic here, you will see where Mr. Nervous is having his problems....

Mr. Nervous,

First of all you need to open the file and read its contents in. Please look up the following on the index tab of the help files and don't forget to look at the examples.

FreeFile Function
Open Statement
Input Function
Line Input Function
Close Statement

Then, use your new best friends (yahoo, google, ask, answers, bing) to search for vb6 ado tutorial.

So your process would be something like this pseudo code...

read file in
open connection to database if not already open
prepare sql insert statement
execute sql insert statement with the connection objects execute method

Good Luck

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.