Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autonumber Question 4

Status
Not open for further replies.

EllieFant

MIS
May 15, 2001
513
0
0
US
I have created an Inspection Database for our Safety Department and am in the process of remaking it to correct some things you don’t do when creating a database (like using the word date as a field name) along with adding some new features.

Somewhere along the line this database has had the need of exporting open findings so that our project controls department can put these items on a schedule. The problem we have ran into doing this is that each Inspection Number can have multiple findings causing a problem for the program (P3) project controls uses since each item needs a unique number. It has also caused the Safety Department some troubles trying to figure out which of the findings project controls assigned what number too (they keep track of the project controls number in the database now too).

I have considered adding a field so that the person entering the inspection into the database can assign a number to finding, but they have a hard enough time trying to remember what fields need to be completed and how (OK they are not exactly computer gurus). I need a better solution.

What I would like to be able to do (and I don’t know how) is to be able to have it like an auto number, but that the number would start over at 1 for each new inspection number. So, I could have something like:

Inspection Number Finding Number Finding
100 1 Safety Glasses not worn in the PAS
100 2 Safety Glasses not worn in the MDB
101 1 Employee not carrying M40
102 1 Employees not wearing seatbelts in vehicles
102 2 Fire Extinguishers not inspected in the upper modules.

When the report would be given to project controls they would see:

100-1 Safety Glasses not worn in the PAS
100-2 Safety Glasses not worn in the MDB
101-1 Employee not carrying M40
102-1 Employees not wearing seatbelts in vehicles
102-2 Fire Extinguishers not inspected in the upper modules.

How would I automate the Finding Number so that it would start over at 1 for each new Inspection Number?

Thanks in advance for your help,


Ellie
**Using Access 97 at work**
**Using Access 2000 at home**

lena.wood@starband.net
 
Ellie:

Are your users assigning the 100, 101, 102 inspection numbers or are those autonumbers produced by Access?


"I know what you're t'inkin', ma petite. Dat Gambit... still de suave one, no?"
 
The inspection numbers are assigned by Access. I was just using those numbers as an example.


Ellie
**Using Access 97 at work**
**Using Access 2000 at home**

lena.wood@starband.net
 
Before posting, I would liek to say that there was someone here (MichaelRed???) who originally posted this idea and sample code. I beleive it was a FAQ, but I can't seem to locate it now. So, to the original poster, you deserve the credit....

EllieFant,

What you are looking for is an autonumber field based on a prefix....each prefix has its own autonumber sequence. While this can't be done using any Default Access tools, you can easily set it up.

It requires a bit of coding, but the result is great. One table with two fields: Prefix (Text) and NextNumber (Long Integer) and default the NextNumber to 2. When you need a new number, you open a recordset to this table. You search for the prefix. If no prefix is found, add it to the table and the first number you return is 1. If the prefix is found, you get the number from the nextnumber column, return that, and add one to the value in the table.

I have a sample database of this if you need an example. Or ask for some more details....always glad to help.

****************************
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III
MCSA, CNA, MCP, Network+, A+
w: robert.l.johnson.iii@citigroup.com
h: wildmage@tampabay.rr.com
 
Ellie:

You can use the following to update the Finding Number on a form, add this to the On Open Event of your Form for adding Findings:

If IsNull(Me.Finding_Number) Then
Dim rsNr As Variant
rsNr = DMax("[Finding_Number]", "FindingsTable", "[Inspection_Number] = '" & me.Inspection_Number & "'")
If IsNull(rsNr) Then
Me.Finding_Nubmer.SetFocus
Me.Finding_Number = 1
Else
Me.Finding_Number = rsNr + 1
End If
Else
End If

make sure and change the names of the Fields and Tables to those in your database.



"I know what you're t'inkin', ma petite. Dat Gambit... still de suave one, no?"
 
Please send me the sample database - that is how I work best - by following an example.

You can send it to me at lena.wood@starband.net - please don't zip it up (unless it is an auto unzip) as our IT department don't allow us to have Winzip or anything of the like on our computers.

Thanks for your assistance! Just love this place and the helpfulness of everyone - I have learned so much here thanks to the kindness of people such as yourself.


Ellie
**Using Access 97 at work**
**Using Access 2000 at home**

lena.wood@starband.net
 
I didn't get the database in the email. Since the email was sent to me from my email address I home, I have to write to you here (no email address on the email I got except my own).

There was a text file attached with the following message:

An attachment named db1.mdb was removed from this document as it constituted a security hazard. If you require this document, please contact the sender and arrange an alternate means of receiving it.

My work email address isn't always reliable for some reason so I have my home email (the address I gave you anyway) auto forwarded from my home. - please include your email address in the message of email so that I can reply to you via my work email address. Sorry to be such a pain...sometimes working in a "government" enviroment isn't that friendly for getting help electronically.


Ellie
**Using Access 97 at work**
**Using Access 2000 at home**

lena.wood@starband.net
 
I am still needing to do this but to a different database. One I am creating from scratch.

The sample database that was sent to me works great, but it uses departments added to a table and then uses the first two letters of that department. I need it to work with the autonumber generated by Access and use the complete number.

I tried the code above, and must not have put it in the right place. Here is the layout of my tables.

InspectInfo (This is the inspection information table))
InspNumber (Autonumber)
ISDate (Inspection Start Date)
IEDate (Inspection End Date)

InspectFindings (This is the findings information table
InspNumber (This is the field the subform and form link to)
FindingNumber (This is the field I want to be 1, 2, 3, and etc and reset when a new inspnumber is generated).

I will then join the InspNumber and FindingNumber using a query to give each finding the "unique" number that will identify the inspection and finding number.

I am at work so if you need more information you can email me here at lena.wood@wgint.com.

Thanks for your help!


Ellie
**Using Access 97 at work**
**Using Access 2000 at home**

elliefant@qwest.net
 
I have a similar database & was able to get everything to work except we want to add a second criteria to the DMax function (not sure how to do this or if it can be done). It currently reads as shown below (I used the code from jfgambit above as a guideline)

**Notes: Index number (will be #1-12), Invoice Number will number from 1+ for each Index number, but it needs to look at year & determine if it is Index #1 of 2003 or 2002.**

Dim rsNr As Variant
rsNr = DMax("[Invoice_Number]", "tblInvoice", "[Index]=" & Me.Index & "")

I thought the following would work for 2 criteria but it gives me an error message "Data type mismatch in criteria expression"

Dim rsNr As Variant
rsNr = DMax("[Invoice_Number]", "tblInvoice", "[Index]=" & Me.Index & " AND [Year]= " & Me.Year & "")

 
EllieFant

I have have used Robert's "autonumber by prefix" code (with some modifications) and I swear by it! It's exactly what I needed, and it sounds like it's what you're looking for.

Robert...tried to email you but the citibank address keeps getting returned.

Jim DeGeorge [wavey]
 
Jim,

I left that company about two months ago...still playing cleanup with email addresses....

There are current ones in my profile. Feel free to shoot me a mail and I will forward a sample to you...

****************************
Only two things are infinite, the universe and human stupidity,
and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III
MCSA, CNA, MCP, Network+, A+
wildmage@tampabay.rr.com
rljohnso@stewart.com
 
I am in need of the "autonumber by prefix" code - could someone be so kind as to send it to me? I am trying create "line numbers" for each record in a subform that is related to a record in the main form.

Thank you for your help!

Raphael Bernard
rbernard@stfrancishealth.org
 
Manaburrn,

sent per your request...let me know if you have any questions.

****************************
When the human body encounters disease it raises its temperature making it uncomfortable not only for the body but also for the disease. So it global warming the Earth's way of saying we are not wanted?

Robert L. Johnson III
MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top