|
-
Jun 16th, 2011, 10:22 AM
#1
Thread Starter
PowerPoster
Insert variable in a connesction string..
I use this code to read a txt file with ADO...
Code:
Sub uno()
Dim CN As ADODB.Connection, RS As ADODB.Recordset
Dim TEST As String, I As Long
Set CN = New ADODB.Connection
CN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\TEMP\;Extended Properties=""text;HDR=Yes;FMT=Delimited"""
Set RS = New ADODB.Recordset
RS.CursorLocation = adUseClient
RS.Open "select * from [ZIPDD001.TXT]", CN, adOpenDynamic, adLockReadOnly, adCmdText
While Not RS.EOF
For I = 0 To RS.Fields.Count - 1
If Not IsNull(RS(I).Value) Then
TEST = RS(I).Value
End If
Next I
RS.MoveNext
Wend
End Sub
now i need to use a varible string instead [ZIPDD001.TXT]
for example:
RS.Open "select * from [name of my var here]", CN, adOpenDynamic, adLockReadOnly, adCmdText
how to midifiy this conn?
-
Jun 16th, 2011, 11:03 AM
#2
Re: Insert variable in a connesction string..
what abt this?
Code:
RS.Open "select * from [" & MyVar & "]", CN, adOpenDynamic, adLockReadOnly, adCmdText
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|