+ Reply to Thread
Results 1 to 6 of 6

How to select date column

  1. #1
    Registered User
    Join Date
    08-14-2014
    Location
    HK
    MS-Off Ver
    2010
    Posts
    6

    How to select date column

    I am using EXCEL VBA and SQL statement to try to select some data in worksheet

    Below is my worksheet sample

    datee name product_name product_code
    2014/6/1 Eric Toy_A C0001
    2014/6/3 Stephen Toy_B C0003
    2014/6/16 Calvin Toy_C C0003
    2014/6/19 Perry Toy_D C0001
    2014/6/23 Calvin Toy_E C0002

    Here is my code segment for select data

    strQuery = "SELECT * FROM[List$] where promoter_name = 'Calvin' and promoter_code = 'C0003'"
    Set rs = cn.Execute(strQuery)

    This is success to select data with no error

    ============================
    But when I changed the condition to use datee column

    strQuery = "SELECT * FROM[List$] where promoter_name = 'Calvin' and datee = '2014/6/23'"

    It cannot work
    The error message said data type incorrect

    How can I do?
    Do I need to set any thing before run the sql?

  2. #2
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: How to select date column

    Try to see if this works....

    Please Login or Register  to view this content.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  3. #3
    Registered User
    Join Date
    08-14-2014
    Location
    HK
    MS-Off Ver
    2010
    Posts
    6

    Re: How to select date column

    I just tried , but its not work
    Display error message about query string error

  4. #4
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: How to select date column

    I think the quotation mark around the date is causing error because date is number not text so try to remove the single quote around the date to see if this works.

  5. #5
    Registered User
    Join Date
    08-14-2014
    Location
    HK
    MS-Off Ver
    2010
    Posts
    6

    Re: How to select date column

    strQuery = "SELECT * FROM[List$] where promoter_name = 'Calvin' and datee = 2014/6/23"

    Don't show any error but It cannot select any data =;="

  6. #6
    Registered User
    Join Date
    08-14-2014
    Location
    HK
    MS-Off Ver
    2010
    Posts
    6

    Re: How to select date column

    I just try successful between date using #
    Thanks first~

    I want to ask one more question
    if I want to input a variable in select query. How can I do?

    I tried
    strQuery = "SELECT * FROM[List$] where promoter_name = '& v_name &' and datee = 2014/6/23"
    But cannot work

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Select which column & row to paste value according the date
    By mbime in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-25-2014, 06:57 AM
  2. Select column based on date
    By miss_gee_gee in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-21-2014, 09:46 PM
  3. Select a Date between Two Date Rows, then the Column State and return Table Matrix Values
    By InNeedofHelpASAP in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-12-2012, 11:03 AM
  4. select date range in column
    By Biff in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-11-2006, 01:40 PM
  5. select date range in column
    By garlocd in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 07-11-2006, 01:35 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1