473,385 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Automatically fill another field in a form

Hi,

In my form users must enter data about new employees.

One of the fields is the birthdate of an employee. The next field is a
registration number that looks like this: 0YYMMDD.

0: first digit that is always a zero unless the registration number already
has been stored, in this case the first digit will be a 1, etc.
YY: year of birth (without century)
MM: month, e.g. 01, 02...12
DD: day, e.g. 01, 02...31.

My purpose is that the field 'registration number' is filled automatically
using the value from the field 'birth date'. It would be great if
automatically is checked whether a registration number already exists and
the first digit is raised from 0 into 1, 2 etc. This last step would be
perfect but if the field 'registration number' is automatically filled with
'0YYMMDD' I will be greatfull.

Thanks.

Frank
Nov 13 '05 #1
1 2090
Use the AfterUpdate event procedure of your birthdate field to lookup the
maximum prefix used so far, and assign the registration number.

This kind of thing:

Private Sub Birthdate_AfterUpdate()
Dim strWhere As String
Dim varResult As Variant
Dim iNextNum As Integer

If Not IsNull(Me.birthdate) Then
strWhere = "[Registration Number] Like ""#" & _
Format(Me.[birthdate], "yymmdd") & """"

varResult = DMax("Registration Number", "MyTable", strWhere)
If Not IsNull(Me.varResult) Then
iNextNum = CInt(Left(varResult, 1)) + 1
End If

If iNextNum < 10 Then
Me.[Registration Number] = Trim(Str(iNextNum)) & _
Format(Me.[birthdate], "yymmdd")
End If
End If
End Sub
In a multi-user environment, you may want to do this in Form_BeforeUpdate
instead, so it is calculated at the last possible moment, to reduce the
chances that 2 users are given the same result.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Frankie" <f.*********@tiscali.nl> wrote in message
news:41**********************@dreader2.news.tiscal i.nl...

In my form users must enter data about new employees.

One of the fields is the birthdate of an employee. The next field is a
registration number that looks like this: 0YYMMDD.

0: first digit that is always a zero unless the registration number
already has been stored, in this case the first digit will be a 1, etc.
YY: year of birth (without century)
MM: month, e.g. 01, 02...12
DD: day, e.g. 01, 02...31.

My purpose is that the field 'registration number' is filled automatically
using the value from the field 'birth date'. It would be great if
automatically is checked whether a registration number already exists and
the first digit is raised from 0 into 1, 2 etc. This last step would be
perfect but if the field 'registration number' is automatically filled
with '0YYMMDD' I will be greatfull.

Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: paul b | last post by:
Hello, I have a small problem in PHP an perhaps someone can help me: I have a simple HTML login page with a username and a password field, as well as a submit button, which I have to use for...
8
by: netsurfer | last post by:
Hi: Have a question on making the date automatically filled in by what the user enters in by the date at the top. The date entered at the top would most likely be on a Wednesday then I need...
1
by: Charles Robinson III | last post by:
When selecting a option from a drop down menu in the form view, which is linked to a table with three columns, how do I get Access to automatically fill in two other fields automatically once the...
2
by: fkealty | last post by:
I'm attempting to make a small user database more efficient. I have an employee table with id numbers, last name first name title and address. Using a combo box I select the last name and have...
7
by: jballard | last post by:
Hello, I have a database set-up with a form and two subforms in it. I have one of the subforms (replacement parts) set-up where you can pick part numbers from a drop down box and also pick a...
10
by: RoadRunner | last post by:
Hi, I have a employee vacation database that has a vacation table that has the employee name, pay week and date of vacation. I have another lookup table with pay week code and date range for the...
1
by: moorebj | last post by:
I am having trouble writing a SELECT query. I have a "Customer" table with "Customer Name", "Street Address" and "Suburb, State, Post Code" fields. On a form I would like to be able to enter in...
4
by: JA | last post by:
Not exactly sure how to explain this. I have 4 fields (in access 2000). Category, Catid, Subcat, subcatid. There are 40 categories, and about 1500 subcats. I've added the categories to the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.