Reading .txt file for a long long sql string

R

rjgst3

Here's my challenge. I have a sql statement that is 2 pages long. I
don't want to go through the process of copying this into my module
(I'm lazy). Example

str_sql = "blah blah blah blah blah blah blah blah blah blah blah blah
" & _
" blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah " & _
"blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah " &
" etc......;"

Instead, I want to reference a .txt file and use the sql from there.
Seem simple....Any suggestions.
 
M

MGFoster

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Why not just use a QueryDef?

Some programmers put SQL strings in tables (Memo fields) and just select
the string into a string variable & then run that.

dim db as dao.database
dim rs as dao.database
set db = currentdb
set rs = db.openrecordset("select SQL from Commands WHERE ID = 2")
strSQL = rs!SQL
' use the strSQL command

If you want to keep you text file, just use the Open # & Input #
commands to get the data into a string. Be sure you concatenate all
lines that make up the SQL command.

dim fd as integer
fd = FreeFile
Open "C:\TheTextFile.txt" For Input As #fd
while not eof(fd) ' read all the lines from the file
Input #fd, strLine
strSQL = strSQL & " " & strLine
wend
' use the strSQL

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBREfY3oechKqOuFEgEQLVxwCg9pHOMxlk60MBWXErUDjcc77zT0wAoJT8
90eUAMRYAFk4JX9SYXv1kggX
=tKV3
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top