Auto Call #

ssworthi

Registered User.
Local time
Yesterday, 23:01
Joined
Jun 9, 2010
Messages
97
Is there a way to have a form create an auto number with a prefix of "CN-####". There is a data base one department uses and it has Case #, Call #, Incident # and I have been requested to create on their form auto numbers. I have some experience in auto #'s but not much and thought best to ask the experts. Thanks so much for any help!:confused:
 
Since you care about the numbers AND you can't control the AutoNumber field going to suggest you use DMax() in the Before_Insert of your form...

Me.YourField = DMax("YourIDField","YourTable") + 1

...and just store the numbers. You can display the lettering you want on the form and/or reports.
 
Perhaps the attached sample will give you some pointers. It uses the DMax() function plus one to increment a counter. The prefix to indicate which office the number relates to is only added for the users benefit when the number is being displayed in a form or report.
 

Attachments

I want to make sure that I understand where I am to do this. In the form properties there is a "Before_Insert" listed in the property fields. That I have a text box for (example Case # )on the form that in the Before Insert I use "Me.Case # = DMax("Case #,"Incident Tbl") + 1"
 
I wrote:
Me.[Case #] = DMax([Case #], [Incident Reports Table]) + 1

It gave me a "compile error". This is so new to me.
 
Yes, but Bracket because of spaces and wildcard characters...

Code:
Me![Case #] = DMax("[Case #]","[Incident Tbl]") + 1
 
Awesome; it worked. The number came out "61-235" Anyway to format it with month and year? That is so great! I just love this forum! Thank you so much!
 
Where and how do you want the month and year to show?
 
In the case # would be great. I don't know how it's calculating the 61-235; where would I look? Thanks so much for your help.
 
Okay, well you didn't say how you wanted it to look so here's try number one...

Code:
Me.[Case #] = DMax("[Case #]","[Incident Tbl]") + 1 & Year(Date()) & "." & Month(Date())
 
I wrote:
Me.[Case #] = DMax("[Case #]","[Incident Reports Table]") + 1 & Year(Date()) & "." & Month(Date())

It replied"Run-Time error '94': Invalid use of null
 
I just started a new record and that's what happened. This is what I wrote:
Me.[Case #] = DMax("[Case #]","[Incident Reports Table]") + 1 & Year(Date()) & "." & Month(Date())

Does this look correct or do I have a type-O?
 
Where exactly are you putting this line because it looks perfect...
 
I open the form in design view, went to form properties, and in the "before index" line I put in that code. Thanks so much for your help with this; I'm so challenged by code.
 
I just tried it again and it looks like some of the () are being dropped in the string.
Me.[Case #] = DMax("[Case #]", "[Incident Reports Table]") + 1 & Year(Date) & "." & Month(Date)
I actually went in and used the debugger and tried to add the () but it saved it with just the (Date).
 
It dropping the parentheses should happen in the Editor so no worries there. Oh dear, I see part of the problem, you can't run DMax against that field because we are adding Month and Year.

There is no Before_Index so did you mean Before_Update and that would be Before_Update of the form. However, with storing Month Year, is this a text field?
 
I put the event "before insert". Should it be before update? It works when I use the before insert without the date; it gives me a number that I have no idea where it comes from but it works.
 
It will work there and you can leave it there... it is the Month/Date that is going to cause the issue. Once I thought about it there is no way for it to get maximum value adding that.

Now I can either write something OR you can store Month/Tear in another column. Which do you prefer?
 

Users who are viewing this thread

Back
Top Bottom