473,396 Members | 1,772 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,396 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 2091
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...
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: 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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.