Count records in each Week

walkerg

New Member
Joined
Dec 22, 2003
Messages
1
Help, i,m new to Access. I have a query which includes a field that projects a startdate for each record. The problem i have is i need to place a constraint on the number of starts that I can have in a particular week. For example, my query currently shows 10 records in the 51nd week of 2003; however, due to production I can only have 5 starts, once I have 5 starts in a particular week then startdate needs to be the subsequent week 52nd week of 2003. Hope this makes sense. Help
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
I can only think of a roundabout way of doing this, but it may get you started. It needs 2 queries --

qryFirst has [MyDate] from the same record source as the form, and a calculated field =DatePart("ww",[MyDate]).
In the Criteria row below the calculated field, put DatePart("ww",[Forms]![MyForm]![MyDate]).
At this point you have all records with the same start week as the current record.

qrySecond has qryFirst as its record source. Place the calculated field on the grid, press the Totals (sigma) button on the toolbar and select Count as the summary function.
Now you have a single field that counts all records with the same start week as the current record. Name this field Tally.

Back to the form. New textbox, with the controlsource =[qrySecond]![Tally]. Call this Counter. Check it out to see if it runs.
Validation: You have 2 options.
(1) At form level, you enter an expression which prevents you from saving a record if the new textbox is >5.
(2) You create another textbox, formatted to be flat, with the same background as the form, with bold red text. This can have whatever message you want. Call this Warning. Now to create some code to drive it. In the Form properties, click the Events tab. Double-click the BeforeUpdate event, then click the ... button at the end of the line to go to the code module. Enter this:
Code:
If [Counter] <=5 Then
   [Warning].Visible=False
Else
   [Warning].Visible=True
End If
Put the same code in the OnCurrent event of the form.

You'll need to change field, query and form names to suit.

Denis
 
Upvote 0

Forum statistics

Threads
1,221,596
Messages
6,160,719
Members
451,666
Latest member
GCS1998

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