RE: Query or VBA code

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Monique,

From your original post, and the responses, it is not entirely clear whether
you are generating bi-weekly or bi-monthly queries. However you are doing
it, it appears that you have a bunch of these queries and are trying to
kludge them together. I would recommend against this, and recommend a
technique similar to what John recommended. A single query to determine the
values for all of the periods in question. Then, use the where clause to
determine which weekly periods actually end up in your report.

Johns response will give you a report with 2 periods per month, but will not
give you records that are in 2 week intervals, if that is what you want. If
that is what you want, then you could use a formula something like:

(Datepart("ww", [DelivDate])-1)\2

to group by. The down side of this is that the first period of the year
would almost never have 14 days in it, unless the year started on a Sunday.

Another way to group this report would be to do something like:

(datediff("d", Dateserial(year(date), 1, 1), [DelivDate])-1)\14

This would give you 2 week periods starting on Jan 1 or any particular year,
but would result in a leftover day (or 2 on leap year) at the end of the
year; so you would have to figure out how to handle that.

A third way to approach this would be to create a table that defines the
dates (this could be complete dates, or could just be the month and day) that
are in each 2 week period. You could include a yes/no field in this table,
to identify which periods you would want to include in the report.

The stucture of this table might be tbl_Periods:

PeriodID, IsSelected, Start_Month, Start_Day, End_Month, End_Day
1 -1 1 1 1
14
2 -1 1 15 1
28
3 -1 1 29 2
11

and your SQL string might look like:

strSQL = "SELECT PeriodID, " _
& "sum(EuroSodCost) AS SumEuroSodCost " _
& "FROM tblDuesSod, tbl_Period as P" _
& "WHERE [DelivDate] >= " _
& "Dateserial(Year(date), P.Start_Month, P.Start_Day) " _
& "AND [DelivDate] <= "_
& "Dateserial(Year(date), P.End_Month, P.End_Day) " _
& "AND P.IsSelected = -1"

Then, you could determine which periods to include by setting the IsSelected
field to true or false.

--
HTH
Dale

Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.



"Monique" wrote:

I have a table of orders called ‘tblDuesod’. I want to calculate the total
cost (EuroSodCost) of the orders which have a delivery date (DelivDate)
between 2 specific dates, then plug plug the result in the control of a
report. I want to do this for each half-month period thru the year.
I made individual queries but cannot figure out how to plug all the results
in a report.
I tried a single query with IIf() and got nowhere.
I turned to code. Here it is but it’s not working. It give me a '€0' in
the report control. I know the connection is working as it finds out that
the field is in euros. Can you help ?

Dim JuneOne As Currency

Dim myConnection As ADODB.Connection
Set myConnection = CurrentProject.Connection
Dim recordset2 As New ADODB.Recordset
recordset2.ActiveConnection = myConnection
recordset2.CursorType = adOpenStatic

recordset2.Open ("SELECT sum(EuroSodCost) AS [JuneOne] FROM tblDuesSod WHERE
(DelivDate) between #6/01/2008# and #6/16/2008#;")

Me![txtJune1] = JuneOne

recordset2.Close

.



Relevant Pages

  • Re: Having acces compute a formula
    ... If you're creating invoices or the like you can create Report ... so I recommend that you invest in some books. ... > ratio of weight per foot using a different form) the I want to be able to ... > am paying for it and the total price that i am selling it for. ...
    (microsoft.public.access.gettingstarted)
  • Re: Are round IDE/floppy cables good?
    ... does anyone report good experiences and recommend them heartily? ... I recently converted from a flat 68-pin SCSI LVD cable, ...
    (alt.comp.hardware.pc-homebuilt)
  • Re: Looking for a link validation tool
    ... > company's corporate website. ... Can someone recommend a tool that will check for and ... > report on the validity of our hyperlinks? ... Sonhos vem. ...
    (alt.html)
  • Re: Is the drive failing?
    ... report and places an indicator at the top of the screen by the date. ... I recommend two utilities: DiskWarrior by Alsoft ... Symantec is where good products go to die, ... Yeah, they made some really valuable products, sooooo long ago. ...
    (comp.sys.mac.hardware.storage)
  • Re: Novice help with list boxes
    ... capturing report requests. ... The database is currently setup so ... I wouldn't recommend it, though... ... Dim varItem As Variant ...
    (comp.databases.ms-access)