Results 1 to 4 of 4

Thread: SQL (A2K)

  1. #1
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Louisville, Kentucky, USA
    Posts
    605
    Thanks
    0
    Thanked 0 Times in 0 Posts

    SQL (A2K)

    I need help PLEASE!!

    I have the following code that works as it should: Keeping in mind the Uid and Pwd MUST be hard coded.....
    <pre>strConn = "Driver={SYBASE ASE ODBC Driver};NA=REPORTSNAME,4100;Uid=ME;Pwd=MYPW;databa se=MYDATABASE;"</pre>


    However, I want to use this code applying a variable for the "UID" and the "PWD" to avoid the HARD CODING. So let's assume UID=ME and Pwd=MYPW:
    I want this:<pre>Dim myLoginID, myPass, Sql as string
    myLoginID="ME"
    myPass="MYPW"

    Sql = "Driver={SYBASE ASE ODBC Driver};" + "NA=REPORTSNAME,4100;" + "Uid=MyLoginID;" + "Pwd=myPass;" + "database=DATABASENAME;"</pre>

    but the connection fails because it doesn't recognize the variables, myLoginID and myPass. I've been told it must be in string format (from looking at it, I thought it was, but what do I know), anyway, I tried this:
    <pre>Sql = "Driver={SYBASE ASE ODBC Driver};" + _
    Sql = "NA=REPORTSNAME,4100;" + _
    Sql = "Uid=myLoginID;" + _
    Sql = "Pwd=myPass;" + _
    Sql = "database=DATABASE;"</pre>

    but the connection fails.

    What am I not understanding or overlooking?
    Roberta Price <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: SQL (A2K)

    You must place the variables outside the quotes:
    <code>
    Sql = "Driver={SYBASE ASE ODBC Driver};" & _
    "NA=REPORTSNAME,4100;" & _
    "Uid=" & myLoginID & ";" & _
    "Pwd=" & myPass & ";" & _
    "database=DATABASE;"
    </code>
    I used & instead of +. Both will work to concatenate strings, but & is the official concatenate operator. Use of + can have unexpected results if you concatenate numeric values.

  3. #3
    4 Star Lounger SteveH's Avatar
    Join Date
    Jan 2001
    Location
    Chelsea, Gtr London, United Kingdom
    Posts
    587
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SQL (A2K)

    <hr>Dim myLoginID, myPass, Sql as string<hr>
    For info - this line declares myLoginID and myPass as variants. Only Sql is typed as a string.

    Dim myLoginID as String
    Dim myPass as String
    Dim Sql as String

    will declare them all as strings.
    Steve H
    IT Lecturer/Access Developer
    O2K SR3/O2010; Win7Pro

  4. #4
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Louisville, Kentucky, USA
    Posts
    605
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SQL (A2K)

    Thanks to both of you guys. Everything works perfectly.

    Steve, thank you pointing that out my declaration issue, I wasn't aware of that. Learning something new every day.

    Have a great day guys.
    Roberta Price <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

Posting Permissions

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