Results 1 to 2 of 2

Thread: Insert variable in a connesction string..

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,941

    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?

  2. #2
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: Insert variable in a connesction string..

    what abt this?
    Code:
    RS.Open "select * from [" & MyVar & "]", CN, adOpenDynamic, adLockReadOnly, adCmdText
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width