+ Reply to Thread
Results 1 to 16 of 16

I need to fetch data from My sql in excel of current date

  1. #1
    Registered User
    Join Date
    08-20-2013
    Location
    Indore
    MS-Off Ver
    Excel 2007
    Posts
    18

    I need to fetch data from My sql in excel of current date

    hi there,

    I am having a problem while fetching the data of the current date from my sql database but when i specify a date in the format "2013-08-20" then it works perfectly and returns the data to excel sheet, can anybody please tell me how to do this.



    Regards:-
    Prashant

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: I need to fetch data from My sql in excel of current date

    Without knowing how you are actually fetching the data, I'm afraid no-one will be able to help you

  3. #3
    Registered User
    Join Date
    08-20-2013
    Location
    Indore
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: I need to fetch data from My sql in excel of current date

    hi,

    here i am sharing my cod with u, please check

    CommandText = Array( _
    "SELECT **********.Entrydate, *******.ORDERNO, *****.DISPOSITION_NAME, ****.CC_NAME" & Chr(13) & "" & Chr(10) & "FROM ***** customiseview" & Chr(13) & "" & Chr(10) & "WHERE (****.Entrydate='2013-08-20') AND" _
    , _
    " (****.DISPOSITION_NAME='Order') AND (****.CC_NAME='Indore')" _
    )

    here at "WHERE (****.Entrydate='2013-08-20') i need a function which can take current date as entry date.

    Prashant

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: I need to fetch data from My sql in excel of current date

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-20-2013
    Location
    Indore
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: I need to fetch data from My sql in excel of current date

    Well i tried to use this code but still it not working

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: I need to fetch data from My sql in excel of current date

    What "isn't working"? You're going to need to be a bit more descriptive than that

  7. #7
    Registered User
    Join Date
    08-20-2013
    Location
    Indore
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: I need to fetch data from My sql in excel of current date

    All right when i entered the above code and refreshed the query then it rerurned nothing

  8. #8
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: I need to fetch data from My sql in excel of current date

    Both my code and your hardcoded text produce identical outcomes, I suspect therefore that your problem lies elsewhere, consider:
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    08-20-2013
    Location
    Indore
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: I need to fetch data from My sql in excel of current date

    SELECT customiseview.Entrydate, customiseview.email, customiseview.DISPOSITION_NAME, customiseview.AGENTID
    FROM GTM.dbo.customiseview customiseview
    WHERE (customiseview.Entrydate='2013-08-20') AND (customiseview.DISPOSITION_NAME='ORDER')

    here is the orignal code and i just replaced
    SELECT customiseview.Entrydate, customiseview.email, customiseview.DISPOSITION_NAME, customiseview.AGENTID
    FROM GTM.dbo.customiseview customiseview
    WHERE (customiseview.Entrydate='" & Format(Now(), "yyyy-mm-dd") AND (customiseview.DISPOSITION_NAME='ORDER')

    Well i am not able to find the exact problem as there is no error poping.

  10. #10
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: I need to fetch data from My sql in excel of current date

    That isn't the code I gave you. Where have you put that? It isn't VBA code it's SQL and you're trying to put VBA in it

    It should be here:
    Please Login or Register  to view this content.
    Last edited by Kyle123; 08-20-2013 at 04:57 AM.

  11. #11
    Registered User
    Join Date
    08-20-2013
    Location
    Indore
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: I need to fetch data from My sql in excel of current date

    Actually i just made two different macro's but i need the same criteria in both
    the code which i just posted was from sql which i got from the edit query option
    so please give me the code for this statement
    SELECT customiseview.Entrydate, customiseview.email, customiseview.DISPOSITION_NAME, customiseview.AGENTID
    FROM GTM.dbo.customiseview customiseview
    WHERE (customiseview.Entrydate='" & Format(Now(), "yyyy-mm-dd") AND (customiseview.DISPOSITION_NAME='ORDER')

    I just want the current date at the place of entry date so that i don't have to edit the query on daily basis

  12. #12
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: I need to fetch data from My sql in excel of current date

    The code does that, you need to put it in the macro - post the code for your full macro and remember to use code tags

  13. #13
    Registered User
    Join Date
    08-20-2013
    Location
    Indore
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: I need to fetch data from My sql in excel of current date

    i just refreshed the query in the macro so it uses only these codes

    Range("B2").Select
    Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False

    but when i edit the query manualy
    then i get the previously posted statements in the SQL query table

  14. #14
    Registered User
    Join Date
    08-20-2013
    Location
    Indore
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: I need to fetch data from My sql in excel of current date

    Here's a newly recorded macro please check it




    Sub Chc_c()
    '
    ' Chc_c Macro
    '
    ' Keyboard Shortcut: Ctrl+Shift+C
    '
    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
    "ODBC;DRIVER=SQL Server;SERVER=*.*.*.*;UID=***;;APP=2007 Microsoft Office system;WSID=E6" _
    , Destination:=Range("$A$1")).QueryTable
    .CommandText = Array( _
    "SELECT customiseview.Entrydate, customiseview.DISPOSITION_NAME" & Chr(13) & "" & Chr(10) & "FROM GTM.dbo.customiseview customiseview" & Chr(13) & "" & Chr(10) & "WHERE (customiseview.Entrydate='" & Format(Now(), "yyyy-mm-dd") AND (customiseview.DISPOSITION_NAME='Order')" _
    )
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .PreserveColumnInfo = True
    .ListObject.DisplayName = "Table_Query_from_Prashant"
    .Refresh BackgroundQuery:=False
    End With
    End Sub
    when it put the cod given by you it gives syntax error i m a beginner to debug this

  15. #15
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: I need to fetch data from My sql in excel of current date

    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    08-20-2013
    Location
    Indore
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: I need to fetch data from My sql in excel of current date

    Thanks bro it worked for me

    Thanks a lot!

+ 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. [SOLVED] Interesting, but how to fetch data from another Excel file?
    By BNCOXUK in forum Excel General
    Replies: 2
    Last Post: 11-29-2012, 05:51 AM
  2. Replies: 0
    Last Post: 03-29-2012, 08:06 AM
  3. Need Excel VBA macro to fetch data from notepad
    By yourskarthik in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-03-2010, 02:00 AM
  4. [SOLVED] fetch data from excel page
    By Mark in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-21-2006, 11:15 AM
  5. Use of Indirect function to fetch data from another Excel file
    By Boon8888 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-20-2006, 03:50 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