Results 1 to 4 of 4
  1. #1
    ravikiran is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    6

    Help with a Data Query!

    Hello Gurus,


    I need a small help with amending a data query to VBA. I want to customize the dates in the following Data Query with variables

    Code:
        With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array(Array( _
            "ODBC;DSN=******;Description=ITF sap data;UID=*******;;APP=2007 Microsoft Office system;WSID=CNU14608JX-W7;DATABASE=Runtime;Network=DB" _
            ), Array("MSSOCN;Address=***-mdadb001,1833")), Destination:=Range("$A$1")). _
            QueryTable
            .CommandText = Array( _
            "SELECT ITFSAP.LineNum, ITFSAP.SAP, ITFSAP.SAPDesc, ITFSAP.StartDate, ITFSAP.LOTNo, ITFSAP.PONo, ITFSAP.EntryDate, ITFSAP.PlannedQty" & Chr(13) & "" & Chr(10) & "FROM Runtime.dbo.ITFSAP ITFSAP" & Chr(13) & "" & Chr(10) & "WHERE (ITFSAP.SAPDesc Not Like '%Te" _
            , _
            "st%') AND (ITFSAP.StartDate>={ts '2012-10-01 00:00:00'} And ITFSAP.StartDate<={ts '2012-10-29 00:00:00'})" & Chr(13) & "" & Chr(10) & "ORDER BY ITFSAP.StartDate" _
            )
            .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_itfsap"
            .Refresh BackgroundQuery:=False
        End With

    I want to refer the start date to be greater than the variable "StartDt" and less than current date


    I am a newbie with SQL queries. Help will be greatly appreciated.


    Thank you,


    Regards,
    Ravi.



    PS: This is a duplicate post. I tried on another excel forum, where I didn't attract any attention. So I am seeking help here. Thank you!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Try

    "st%') AND (ITFSAP.StartDate>={ts '" & StartDt & "'} And ITFSAP.StartDate<={ts '" & Date() & "'})" & Chr(13) & "" & Chr(10) & "ORDER BY ITFSAP.StartDate"

    I'm not familiar with some of what you have, but that should concatenate the respective values into the string you had. By the way, the Chr() functions are unnecessary; the database engine will ignore them anyway.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ravikiran is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    6
    Thank you Baldy, that worked perfectly well.

    Yeah, I am about to ask my second query about the Char() functions. Sure I removed them.

    Regards,
    Ravi.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Happy to help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 27
    Last Post: 08-14-2012, 09:05 AM
  2. Replies: 13
    Last Post: 10-26-2011, 03:49 AM
  3. Replies: 5
    Last Post: 10-06-2011, 05:49 PM
  4. Replies: 2
    Last Post: 01-31-2011, 08:31 AM
  5. UnMatched Data Query (Edit Data)
    By pedraza4 in forum Queries
    Replies: 3
    Last Post: 06-16-2010, 07:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums