Results 1 to 4 of 4

Input Date Parameters

Threaded View

  1. #1
    Registered User
    Join Date
    12-10-2012
    Location
    Canada
    MS-Off Ver
    Microsoft Excel: Mac 2011 & Microsoft Excel 2010
    Posts
    13

    Input Date Parameters

    Hi Everybody,
    I have written a macro which pulls data from a database in to an Excel sheet and then performs certain actions on it. The SQL query that I have used to pull the data uses date parameters. I have to edit the date parameters in the macro every time I run the query. Can someone please advise, how can I tweak the macro to prompt for date input, every time it is run?

    The SQL script in the macro is as below. I have colored the parts red, where the date input is required.


    ActiveWorkbook.Worksheets.Add
     
        ActiveSheet.Name = "Data"
        Sheets("Data").Select
       
        With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array(Array( _
            "ODBC;DSN=XXXXXXXXXX;DFQ=\\BACKUPSERVER\ABC\RST\XYZ.QBW;SERVER=QODBC;Optim" _
            ), Array( _
            "izerDBFolder=%UserProfile%\QODBC Driver for QuickBooks\Optimizer;OptimizerAllowDirtyReads=N;SyncFromOtherTables=Y;ForceSDKVersi" _
            ), Array("on=;IAppReadOnly=Y")), Destination:=Range("$A$1")). _
            QueryTable
            .CommandText = Array( _
            "SELECT InvoiceLine.TxnDate, InvoiceLine.RefNumber, InvoiceLine.SalesRepRefFullName, InvoiceLine.CustomerRefFullName, InvoiceLine.InvoiceLineItemRefFullName, InvoiceLine.InvoiceLineDesc, InvoiceLine.In" _
            , _
            "voiceLineQuantity, InvoiceLine.InvoiceLineRate, InvoiceLine.InvoiceLineAmount, InvoiceLine.CustomFieldInvoiceLineCommission" & Chr(13) & "" & Chr(10) & "FROM InvoiceLine InvoiceLine" & Chr(13) & "" & Chr(10) & "WHERE (InvoiceLine.TxnDate>={d '2014-03-28'} " _
            , _
            "And InvoiceLine.TxnDate<={d '2014-04-03'})" & Chr(13) & "" & Chr(10) & "ORDER BY InvoiceLine.SalesRepRefFullName, InvoiceLine.TxnDate, InvoiceLine.CustomerRefFullName" _
            )
            .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_XYZ"
            .Refresh BackgroundQuery:=False
        End With
        ActiveSheet.ListObjects("Table_Query_from_XYZ").Unlink
       
        
        Dim oSh1 As Worksheet
        Set oSh1 = ActiveSheet
        'remove table or list style
        oSh1.ListObjects("Table_Query_from_XYZ").Unlist
    I would highly appreciate if you someone can help !!!!
    Thanks... Murtaza
    Last edited by murtaza.khan; 04-07-2014 at 06:51 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Automation of Macro input parameters
    By cda123 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-26-2011, 01:50 PM
  2. Dynamic Web Query with multiple input parameters
    By Lukasz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-01-2010, 12:12 AM
  3. Replies: 2
    Last Post: 03-08-2010, 11:25 AM
  4. Input parameters to an excel Application
    By eitancoh in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-22-2007, 06:35 PM
  5. XIRR function input parameters
    By kieran sweeney in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 04-29-2005, 07:06 AM

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