View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Get data for only last three months

Possibly:

cn.Open cString

j = 0
For m = curMonth - 3 To curMonth - 1
j = j + 1
MerchantMonthly = "select branch, sum(qty), sum(b.vat)" & _
" from service_providers a left outer join cb b on a.sp_name = b.sp_name
and month" & _
" (inv_date) = " & m & " and year(inv_date) = " & curYear & " order by
a.sp_name"

If rs.State = -1 Then rs.Close

rs.Open MerchantMonthly, cn, adOpenKeyset, adLockOptimistic, adCmdText


'dump data into excel by calling function
Call PopulatePage(j) '<=== change m to j

--
Regards,
Tom Ogilvy


"poppy" wrote in message
...

Hi Jim and Tom

Thanx for your quick reply.

I tried your code and it works fine: For m = curMonth - 3\ -4 To
curMonth - 1.

The only problem is that a couple of columns in the spreadsheet are
skipped before the data is inserted. In other words when I say it must
only give me data for the last three months, it skips 7 columns before
displaying the data.


--
poppy
------------------------------------------------------------------------
poppy's Profile:

http://www.excelforum.com/member.php...o&userid=11453
View this thread: http://www.excelforum.com/showthread...hreadid=266048