How to add fields for user-specified date range in macro to import data from AS400 thru ODBC?????

cactusman

New Member
Joined
Oct 15, 2012
Messages
20
Morning, all!

I have the below macro that returns data from my AS400...the problem is it goes back to 2011....I need to create a method of asking the user what months and years they want data from. I thought the little calendar-type control:
date-edit.png


would be a nice touch, but not a requirement.

The macro:

Code:
Sub GetData()
'
' GetData Macro
' Gets Sheet 1 data from Infor
'


'
    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:="ODBC;DSN=INFOR;", _
        Destination:=Range("$A$5")).QueryTable
        .CommandText = Array( _
        "SELECT MOROUT.ORDNO, MOROUT.RLHTD, MOROUT.SRLHU, MOMASTLB.MOSTMY, MOMASTLB.OCDTMY" & Chr(13) & "" & Chr(10) & "FROM S10A7F0P.AMFLIB.MOMASTLB MOMASTLB, S10A7F0P.AMFLIB.MOROUT MOROUT" & Chr(13) & "" & Chr(10) & "WHERE MOROUT.ORDNO = MOMASTLB.ORDRMY AND ((MOMASTLB.MOSTMY='" _
        , "55'))")
        .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_INFOR"
        .Refresh BackgroundQuery:=False
    End With
    Range("E5").Select
    ActiveCell.FormulaR1C1 = "Variance"
    Range("E6").Select
    ActiveCell.FormulaR1C1 = "=[@RLHTD]/[@SRLHU]"
    Range("E7").Select
    ActiveWindow.SmallScroll Down:=-30
    Range("F5").Select
    ActiveCell.FormulaR1C1 = "Completed Date"
    Range("F6").Select
    ActiveCell.FormulaR1C1 = _
        "=DATE(LEFT(RC[-1],3),MID(RC[-1],4,2),RIGHT(RC[-1],2))"
    Range("F7").Select
    Columns("F:F").ColumnWidth = 20.14
    Range("H7").Select
End Sub

Any assistance anyone can provide is greatly appreciated!


Thanks in advance!


Matt
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,216,095
Messages
6,128,792
Members
449,468
Latest member
AGreen17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top