Resetting a numeric field to 1 at the beginning of every month

AOGFADUGBA

Board Regular
Joined
Sep 30, 2015
Messages
74
HI ALL. I HAVE A TABLE WITH AN INDEX FIELD CALLED DEPTNO, WITH ANOTHER NUMERIC KEY CALLED PVNO.
THE PVNO INCREASES BY ONE BY AN AFTER-UPDATE EVENT OF A PDATE FIELD:

Private Sub PDate_AfterUpdate()

If Me.NewRecord = True Then
Me.PVNo = Nz(DMax("PVNo", "CedisPayment"), 0) + 1
End If
End Sub

WHAT I WANT NOW IS FOR THE PVNO TO RESTART AT THE BEGINNING OF EVERY MONTH. AND THE DEPT NO TO RESTART AT THE BEGINNING OF EACH YEAR. IS IT POSSIBLE WITH ACCESS?
THANKS
 
Thanks Boyd. The vba code you helped with is for the addition form for a table. There is another table with the same form and fields. The first table is for actual payment while the second table is for pending payments. Now, records in pending payments are moved to payment table with an append query when payment is made, but there will always be a duplicate PVNo in the Payment table with the append query action. this is what i want to prevent. Hope it makes sense.



The real issue is that you are moving record between table. This should be avoided and never done. I NEVER do this. In 30+ years creating accounting system I have never needed to move records between table.

It actual violates the rules off normalization when you use a table name as data for the record. In yur case the status of pendin should come from a field not the table name.

I see it liek this:
Payments are payment. Pending or not. The status of pending does not change what table the record should be in. All payment belong in the same table.

Do you have a better idea of how to go about this?

YES! There is a much better and simpler solution that used the power of a Relational Database and queries. Use a status field or calculate it as needed.

I see this a lot with people that come from an Excel background and not a relational database background.

When the status changes you want the record to move to a different report page. In Excel this was done my moving the data to the different section.

Moving data is ALWAYS DANGEROUS and ERROR prone.

In a well designed database you simple change the status field. You are done. Even better it is calculated bases on other data.

The report's query can filter that data to the correct place. same for forms. It also makes changing the status back to pending very simple. No meed to move records around again.

By using the power of queries to filter data, to the user/form is can look like the records are in different tables while in reality they are all in the same table.
 
Last edited:
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Great Advise, you got me. Am used to excel and relatively new in access. Though am gradually finding my way around it. Thanks to this forum. But how to go about your suggestion is an issue for me? can you please help.
Thanks
 
Upvote 0
Sure. This may be easier than you think.

What determines is a payment is pending?

For exmapke there may be a data paid field. If null then the payment is pending. Once the data is filled in the it has been completed. Is that is true for you then you have everything you need already.
 
Upvote 0
Thanks, Boyd that is the way to go. I created a field called status. then added an afterupdate event to the actual payment form to update the field with paid. The pending form also has an afterupdate event which updates the status to unpaid. so am using two forms for one table. whenever payment is made on the pending record another afterupdate event changes the unpaid status to paid. Thanks a million for the great advise worked fine.
 
Upvote 0

Forum statistics

Threads
1,221,838
Messages
6,162,286
Members
451,759
Latest member
damav78

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