Results 1 to 4 of 4

Using a cell value as criteria in a data import script

Threaded View

  1. #1
    Registered User
    Join Date
    05-12-2008
    Posts
    3

    Using a cell value as criteria in a data import script

    Hi, I'm hoping someone will be able to help me with what is probabaly a straight forward task in VBA. I have little experience of macros other then to record 'Get external data' imports.

    I'm trying to amend this code so that the user can enter a Start Date into a cell C3 and then the data import gets info from a table where the TxnDate is >= to that value. I've tried a few things but I just keep getting error messages!

    This is what I’ve got to work with:

    
    Sub update()
    
    Dim StartDate As Date
    
    StartDate = Range("C3").Value
    
    Sheets("Sheet2").Select
    
    With ActiveSheet.QueryTables.Add(Connection:="ODBC;;;;" , _
    Destination:=Sheets("Sheet2").Range("A1"))
    .CommandText = Array( _
    "SELECT SMPRODTXNS.PRODUCTCODE, SMPRODTXNS.TXNNUMBER, SMPRODTXNS.LocationCode, SMPRODTXNS.BatchSerialNr, SMPRODTXNS.TypeOfPost, SMPRODTXNS.Account, SMPRODTXNS.TxnDate, SMPRODTXNS.Reference1, SMPRODTXNS" _
    , _
    ".Reference2, SMPRODTXNS.EachUnitFlag, SMPRODTXNS.SalesValue, SMPRODTXNS.CostValue, SMPRODTXNS.PeriodNr, SMPRODTXNS.QtyEach, SMPRODTXNS.QtyUnit, SMPRODTXNS.Year" & Chr(13) & "" & Chr(10) & "FROM SMPRODTXNS SMPRODTXNS" & Chr(13) & "" & Chr(10) & "")
    .Name = "Query"
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .PreserveColumnInfo = True
    .Refresh BackgroundQuery:=False
    End With
    End Sub
    The date field is TxnDate. What do I need to do so that it will only get results after the date in cell C3?

    As previously mentioned, my VBA knowledge is limited at best so please go easy

    Thanks in advance

    Ric
    Last edited by Rick_104; 05-12-2008 at 05:02 AM.

Thread Information

Users Browsing this Thread

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

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