Thank you Brother
, Here is code I'm using:
Code:
Private Sub FlexToExcel()
Dim cnn As New ADODB.Connection
Dim xlApp As New Excel.Application
Dim xlwk As New Excel.Workbook
Dim xlSheet As New Excel.Worksheet
Dim rs1 As ADODB.Recordset
Dim rs2 As ADODB.Recordset
Dim strSQL As String
Dim lngnumCount As Long
Dim intCount As String
Dim ctr As Long
Dim ctr1 As Long
'Dim i As Integer
'Dim strSeriesCell As String
strDate = Format(Date, "mm/dd/yyyy")
cnn.ConnectionTimeout = 15
cnn.CommandTimeout = 30
g_strDBName = dbPath & "\BarqCell Data\DSS.mdb;Jet " & "OLEDB:Database Password=brss"
'creates a new databse conection and sets the conection string
Set cnn = New ADODB.Connection
Constring = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=" & g_strDBName
cnn.ConnectionString = Constring
'Opens the database conection
cnn.Open
xlApp.Interactive = True
Set xlwk = xlApp.Workbooks.Open(App.path & "\midmonth.xls")
Set xlSheet = xlwk.Worksheets("Sheet3")
xlSheet.Select
xlApp.Range("B5").Value = DTPicker1.Value
xlApp.Range("B6").Value = DTPicker2.Value
S_Date = DTPicker1.Value
E_Date = DTPicker2.Value
strSQL = "SELECT DISTINCT number FROM TbStore WHERE strDate between " & "#" & S_Date & "#" & " and " & "#" & E_Date & "# ORDER BY number"
Set rs1 = New ADODB.Recordset
rs1.Open strSQL, cnn, adOpenStatic, adLockOptimistic
ctr = 12 ' start data after headings
'
strSQL = "SELECT Count(number) as intCount FROM TbStore WHERE number = '" & rs1![number] & "' "
strSQL = strSQL & " AND strDate between " & "#" & S_Date & "#" & " and " & "#" & E_Date & "#"
Set rs2 = New ADODB.Recordset
rs2.Open strSQL, cnn, adOpenStatic, adLockOptimistic
lngnumCount = rs2![intCount]
xlApp.Range("B13").Value = lngnumCount
Do While Not rs1.EOF
ctr = ctr + 1
xlApp.Range("C" & Trim(Str(ctr))).Value = rs1![number]
rs1.MoveNext
Loop
rs1.Close
Set rs1 = Nothing
xlApp.Visible = True
End Sub