Custom Autonumber Conditional Formatting

D

drrajnishpatel

To,
The EXPERTS, ( Access Dept.)

I am New to access but have managed to make a database for my patients
records , my trouble is the Registration Number of the Patient,( a cloumn in
my database). i want it to generate the unique ID just llike AUTONUMBER, with
the format i need that should be like YYMMnn( YY= present year,MM= present
month and nn = numbers 01 to 99, with reset to 01 at the start of the next
month)the event to trigger the event is SAVE Form button. please can anybody
help? Thanking you in advance
 
S

S.Clark

I create a table, and store the next available value. In a single user
environment, you can easily retrieve the next number, and update the value
back to 0 at the start of the month.

If you have multiple users, you will need to add more precaution to the
retrieval to prevent dups.
 
K

Klatuu

Use the Form Current event.

Dim strHighNumber as String

If Me.NewRecord Then
strHighNumber = Nz(DMax("[RegistrationNumber]", "tblPatient", _
"Left([RegistrationNumber, 4) = '" & Format(Date, "yymm") &
"'"),"")
If strHighNumber = vbNullString Then 'No numbers for this year/month
strHighNumber = Format(Date, "yymm01")
Else
strHighNumber = Left(strHighNumber,4) & _
Format(Right(strHighNumber, 2) + 1, "00")
End If
Me.txtRegNumber = strHighNumber
End If
 
D

drrajnishpatel via AccessMonster.com

To,
Mr.Klatuu
Thanks for your Promt help... I will try to put this into use in my forms,
but hwever, thanks again for the help.... Since i am new i still find
slightly difficult , on my Main form page in access where excatly do i place
this script, is it to be [placed in the properties of the registration field ,
?
rajnish

wrote:
Use the Form Current event.

Dim strHighNumber as String

If Me.NewRecord Then
strHighNumber = Nz(DMax("[RegistrationNumber]", "tblPatient", _
"Left([RegistrationNumber, 4) = '" & Format(Date, "yymm") &
"'"),"")
If strHighNumber = vbNullString Then 'No numbers for this year/month
strHighNumber = Format(Date, "yymm01")
Else
strHighNumber = Left(strHighNumber,4) & _
Format(Right(strHighNumber, 2) + 1, "00")
End If
Me.txtRegNumber = strHighNumber
End If
To,
The EXPERTS, ( Access Dept.)
[quoted text clipped - 6 lines]
month)the event to trigger the event is SAVE Form button. please can anybody
help? Thanking you in advance
 
K

Klatuu

It goes in the Current Event of the form.
Open the form in design view
select the properties dialog and be sure the form is selected
Go to the Events tab
select the Current event and click the command button to the right of it
with the 3 dots
Select Code Builder
The VBA editor will open with the cursor in the event sub
Put the code in there
--
Dave Hargis, Microsoft Access MVP


drrajnishpatel via AccessMonster.com said:
To,
Mr.Klatuu
Thanks for your Promt help... I will try to put this into use in my forms,
but hwever, thanks again for the help.... Since i am new i still find
slightly difficult , on my Main form page in access where excatly do i place
this script, is it to be [placed in the properties of the registration field ,
?
rajnish

wrote:
Use the Form Current event.

Dim strHighNumber as String

If Me.NewRecord Then
strHighNumber = Nz(DMax("[RegistrationNumber]", "tblPatient", _
"Left([RegistrationNumber, 4) = '" & Format(Date, "yymm") &
"'"),"")
If strHighNumber = vbNullString Then 'No numbers for this year/month
strHighNumber = Format(Date, "yymm01")
Else
strHighNumber = Left(strHighNumber,4) & _
Format(Right(strHighNumber, 2) + 1, "00")
End If
Me.txtRegNumber = strHighNumber
End If
To,
The EXPERTS, ( Access Dept.)
[quoted text clipped - 6 lines]
month)the event to trigger the event is SAVE Form button. please can anybody
help? Thanking you in advance
 
D

drrajnishpatel via AccessMonster.com

To,
Mr.Dave Hargis, Microsoft Access MVP,

Thanks i am thankful to you for your kind support.....this will definately
help....

Dr.Rajnish Patel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top