I started a database for entering ambulance run reports last month. So far, everything is going great with it. As expected, I am always trying to improve upon it as I learn more things.
What I need help on now is auto generating the incident number. Starting the new year, the first incident number will be 20080001. I want to make it where when we create a new record, the default value will see what the last record's incident number is and add 1 to it. We create a new record by clicking a button on the Main Switchboard.
Something to consider...when 2009 starts, i want to be able to make the incident number 20090001.
I appreciate any help in this matter.
Mike Busby
PS. I asked a question on this site a few weeks back: HERE
Within a day or two, the question was answered.
I wanted to again thank everyone that helps out around here. It is much appreciated.
3 19136
I started a database for entering ambulance run reports last month. So far, everything is going great with it. As expected, I am always trying to improve upon it as I learn more things.
What I need help on now is auto generating the incident number. Starting the new year, the first incident number will be 20080001. I want to make it where when we create a new record, the default value will see what the last record's incident number is and add 1 to it. We create a new record by clicking a button on the Main Switchboard.
Something to consider...when 2009 starts, i want to be able to make the incident number 20090001.
I appreciate any help in this matter.
Mike Busby
PS. I asked a question on this site a few weeks back: HERE
Within a day or two, the question was answered.
I wanted to again thank everyone that helps out around here. It is much appreciated.
ASSUMPTIONS:- Table Name: tblIncidents.
- Field Name containing Incident Number: [Incident#].
- You like to keep things neat and tidy in 1 line.
- In the Field on your Form bound to [Incident#], place this Expression in the Data Tab, Default Value Option:
-
Left$(DLast("[Incident#]", "tblIncidents"),4) & Format$(Val(Right$(DLast("[Incident#]", "tblIncidents"),4) + 1),"0000")
- Now, whenever you add a New Incident, the Incident Number will automatically be incremented by 1, and formatted correctly, as in:
- 20080027 ==> New Incident Number will be 20080028
- To keep things simple, add the 1st Record for 2009 manually, then the Default Value Expression will increment it properly, as in:
- 20090001 (manually entered) ==> New Incident Number will be 20090002
- You can also Reset the Counter for a new Year but then neat and tidy, on 1 line, goes out the door. It all depends on what you want.
P.S. - Make sure that the [Incident#] Field is TEXT and not NUMERIC.
I started a database for entering ambulance run reports last month. So far, everything is going great with it. As expected, I am always trying to improve upon it as I learn more things.
What I need help on now is auto generating the incident number. Starting the new year, the first incident number will be 20080001. I want to make it where when we create a new record, the default value will see what the last record's incident number is and add 1 to it. We create a new record by clicking a button on the Main Switchboard.
Something to consider...when 2009 starts, i want to be able to make the incident number 20090001.
I appreciate any help in this matter.
Mike Busby
You are basically asking exactly the same thing that I had to get help with last year. We use exactly the same format for our file numbers, but with a dash: 2008-0001.
The person who originally created our database used some spaghetti programming using an autonumber field to then create the new file number. The problem was that system doesn't leave any room for error, no room for manually correcting file numbers. In order to reset the file numbers back to 0001 at the beginning of the year we had to go into the coding and change the mathematical formulas that were using the autonumber field.... it was a mess. Finally this forum helped me straighten it all out.
I will look to see if the thread for that is still on this forum and I'll link it if it is. If not I'll try to help by posting examples of my code.
It's not as neat as the one liner below, but it works great and does automatically reset at the beginning of the year.
Here is the thread http://www.thescripts.com/forum/thre...le+number.html
Below is what I ended up with. Keep in mind that I am actually using two tables (SC_OPEN and SC_ARCH), and looking for the highest file number between the two. You are probably using one table, so you'd have to filter out the extra stuff. -
Dim stHighest As Integer
-
Dim stHighOpen As Integer
-
Dim stHighArch As Integer
-
-
' Check to see if this is the first order of the year
-
-
If DCount("*", "SC_OPEN", "Left([FILE_NO],4)=Format(Date(),'yyyy')") = 0 _
-
And DCount("*", "SC_ARCH", "Left([FILE_NO],4)=Format(Date(),'yyyy')") = 0 Then
-
-
Me.FILE_NO = Year(DATE) & "-0001" ' Reset file number to 1
-
DoCmd.RunCommand acCmdSaveRecord
-
-
Else
-
-
' Find the highest file number for the current year from both tables
-
stHighOpen = Nz(DMax("Right([FILE_NO], 4)", "SC_OPEN", "Left([FILE_NO], 4) = Format(DATE(), 'yyyy')"))
-
-
stHighArch = Nz(DMax("Right([FILE_NO], 4)", "SC_ARCH", "Left([FILE_NO], 4) = Format(DATE(), 'yyyy')"))
-
-
' Pick the one that is highest
-
If stHighOpen < stHighArch Then
-
stHighest = stHighArch
-
-
Else
-
stHighest = stHighOpen
-
-
End If
-
-
' Create new file number
-
If stHighest > 0 And stHighest < 9 Then
-
Me.FILE_NO = Year(DATE) & "-000" & stHighest + 1
-
End If
-
-
If stHighest > 8 And stHighest < 99 Then
-
Me.FILE_NO = Year(DATE) & "-00" & stHighest + 1
-
End If
-
-
If stHighest > 98 And stHighest < 999 Then
-
Me.FILE_NO = Year(DATE) & "-0" & stHighest + 1
-
End If
-
-
If stHighest > 998 Then
-
Me.FILE_NO = Year(DATE) & "-" & stHighest + 1
-
End If
-
-
DoCmd.RunCommand acCmdSaveRecord
-
-
End If
-
-
Confirm_File_No_Creation:
-
DoCmd.SetWarnings True
-
MsgBox ("The File Number " & [FILE_NO] & " Has Been Created For The Order")
-
This could be improved I'm sure. But I was pleased with it, considering I was brand new at Access
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Tony Clarke |
last post by:
Hi,
Background:
I have written a Call Logging and Reporting System using PHP that integrates
with an existing MS Access Database. The information in the database is all
held in flat tables...
|
by: David Messner |
last post by:
Ok I know this is simple but the statement eludes me...
I have a date field where I want the default value on the data entry form's
date field to be the last date entered. I figure I can do this...
|
by: John Burns |
last post by:
This should be a nice easy one for you lot.
I have got a Combo box, with its source as a value list - there are only two
options, AM and PM.
I want to set a default value in the box, depending...
|
by: anita |
last post by:
Hello All
Can anybody please help me out with this small and ofcourse a crucial
problem for me.
I have two tables in the database system.
Table1 has following fields
Field1 -...
|
by: Miguel Dias Moura |
last post by:
Hello,
I have a dataset (users) on an ASP.NET/VB page (detail.aspx).
A record on this dataset (users) has 3 fields: "id", "username",
"visits".
The page detail.aspx is called with a...
|
by: Shapper |
last post by:
Hello,
I have a database table with 2 fields: and ;
I need to create a function which increases by 1 the number in
field for a certain id.
In this moment I have the following:
Private...
|
by: Ecohouse |
last post by:
I have a main form with two subforms. The first subform has the child
link to the main form identity key.
subform1 - Master Field: SK
Child Field: TrainingMasterSK
The second subform has a...
|
by: zoeb |
last post by:
Hi.
I have a form which the user enters 2 years worth of data into (one record per year). The aim, is to populate the table this form is based on with 3 more years worth of data (i.e. creating 3...
|
by: ellie |
last post by:
Hello
I have a table (MainTable) with the fields
(PK)ID
(cbo)from_dept
document_date
reference_number
last_reference
I have a query on the first 4 fields that is sorted to give the last...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |