Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
My Qustion..

Table Name
J_voucher

Fields are:
Voucher Number, Date , Narration , Debit , Credit

Autonumber on Voucher Number:
I want Autonumber Like That JV-TodayDate-000AutoNumber
Posted
Updated 23-Mar-11 20:53pm
v3

1 solution

Access provides autonumber: it is called an "autoNumber" field, surprise, surprise. Also unsurprisingly, it is numeric only...

I would keep the Voucher code separate: The Voucher number is the Autonumber field, the Date field is the TodayDate, and build the voucher code from that using string.Format:
string voucherCode = string.Format("JV-{0}-000{1}", date.ToString("yyyy-MM-dd"),voucherNumber);

I would also recommend using a Guid as the PK field if you will need to retrieve the information once you have created it.

I would also recommend making the voucher code a little more complex: If I received a voucher with that format, I might be tempted to try the same date, but one digit less / more if I was a naughty type who wanted to cheat you...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900