Results 1 to 2 of 2

Thread: .commandText and variables

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2020
    Posts
    4

    .commandText and variables

    Hello,

    Im quite new to working with VB. Im currently fumbling about with pulling and pushing data to acces via VB.

    I want to use a query string containing variables, so I can pull specific data based on an overview, without having to write out all the 'options' that are available.

    So far I've managed to get a db connection and I can pull some data from my database via;

    .CommandText = "SELECT * FROM [Clean_trade_Data] WHERE [Ticker_ID]='ARD'"

    Yet when I change the code so that the commandtext has to work a variable;


    Dim strcmtxt As String
    strcmtxt = """SELECT * FROM [Clean_trade_Data] WHERE [Ticker_ID]='ARD'"""
    .CommandText = strcmtxt


    I get an error message saying that the operation "SELECT * FROM [Clean_trade_Data] WHERE [Ticker_ID]='ARD'" is not valid.



    I can't seem to find why this doesn't work. Can anyone enlighten me?

    thank you in advance!

    regards!

    Charunks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: .commandText and variables

    Why do you have extra quotes in there? Why would you do this:
    Code:
    .CommandText = "SELECT * FROM [Clean_trade_Data] WHERE [Ticker_ID]='ARD'"
    and then do this:
    Code:
    strcmtxt = """SELECT * FROM [Clean_trade_Data] WHERE [Ticker_ID]='ARD'"""
    What exactly are you trying to achieve by adding extra quotes when you want to use the same value to do the same thing?

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