473,507 Members | 2,447 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Alphanumeric auto number not incrementing

3 New Member
Hi All,

I'm looking for some help correcting my code below.

What I'm trying to accomplish is when a user selects a value from a dropdown field on a form that value of the field code in the table Support Detail is checked by the code and incremented by 1

The field code is a concatenation of Region (NA, EU, AP) the letters MN and a numeric value.

What I'm getting from my code below is the Region selected, 'MN' and 1. Example EUMN1

Expand|Select|Wrap|Line Numbers
  1. Private Sub Region_AfterUpdate() 'autonumber
  2. If Me.NewRecord Then
  3.     Me.Code = Me.Region & "" & "MN" & Nz(DMax("val(Right('[fieldnamedcode]',Len('[fieldnamedcode]')-4))", "[Support Detail]") + 1, "0000")
  4. End If
  5. End Sub
  6.  
I've also tried
Expand|Select|Wrap|Line Numbers
  1. Private Sub Region_AfterUpdate() 'autonumber
  2. If Me.NewRecord Then
  3.     Me.Code = Me.Region & "" & "MN" & Nz(DMax("val(Right('[fieldnamedcode]',4))", "[Support Detail]") + 1, "0000")
  4. End If
  5. End Sub
  6.  
fyi, the above "fieldnamedcode" is just code, but I can't post it that way as it causes and issue for the forum
Any assistance you can give me is appreciated
Thanks
Jun 8 '10 #1
7 3399
gnawoncents
214 New Member
It would be much simpler to add a field to your table that contains a numeric value, rather than trying to break down a text then combine it again. For example, add a field called CodeValue which you increment by 1 whenever your conditions are met. Then, whenever you need to display the “Code” you use the following:

Expand|Select|Wrap|Line Numbers
  1.  Me.Code = Me.Region & "MN" & me.CodeValue
  2.  
I eliminated the extra quote marks as they were not doing anything.
Jun 9 '10 #2
NeoPa
32,557 Recognized Expert Moderator MVP
I had to LoL at your problem with the field named [code]. You're absolutely right that it is used in the BB Code that the site uses.

Domain Aggregate functions can be a bit of trouble to use. The first question that comes to my mind, when attempting to help you towards a solution, is :
Is the number required the next number sequentially from whatever was last used (as the question implies) or is it the more usual requirement of the next number in sequence that matches the Region value selected?

The format of the command would need to be more like :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Region_AfterUpdate() 'autonumber
  2.   If Me.NewRecord Then
  3.     Me.Code = Me.Region & "MN" & _
  4.               Format(Nz(DMax("Right([code],4)", _
  5.                              "[Support Detail]"), 0) + 1, "0000")
  6.   End If
  7. End Sub
Your original code had parameters for the functions in the wrong order so they didn't match what was expected. Otherwise you weren't too far off base.

PS. Don't forget to answer the question posed earlier in the post.
Jun 10 '10 #3
StephD8459
3 New Member
NeoPa,
So to answer your question, Ideally I'd like it to number by region, but if this is to convoluted to create, the next number should be sufficient.

On the code sample you posted I am getting a Runtime Error
Runtime error '13':
Type Mismatch

Any suggestions?

Thanks
Jun 10 '10 #4
NeoPa
32,557 Recognized Expert Moderator MVP
Steph, It's always a good idea to indicate which line the error occurs on when posting error information. I may be able to guess, but always worth doing anyway.

I think I may have left out a Val() call. Try instead :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Region_AfterUpdate() 'autonumber
  2.   If Me.NewRecord Then
  3.     Me.Code = Me.Region & "MN" & Format(Val(Nz( _
  4.               DMax("Right([code],4)", _
  5.                    "[Support Detail]"), "0")) + 1, "0000")
  6.   End If
  7. End Sub
Jun 10 '10 #5
NeoPa
32,557 Recognized Expert Moderator MVP
For numbering sequentially by Region try :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Region_AfterUpdate() 'autonumber
  2.   If Me.NewRecord Then
  3.     Me.Code = Me.Region & "MN" & Format(Val(Nz( _
  4.               DMax("Right([code],4)", _
  5.                    "[Support Detail]", _
  6.                    "[code] Like '" & Me.Region & "MN????'"), "0")) + 1, "0000")
  7.   End If
  8. End Sub
Jun 10 '10 #6
StephD8459
3 New Member
NeoPa,
Sorry about not specifically calling out the error location, but your guess was good :)
I am no longer getting an error, but it is still not incrementing.
I am getting '0001' for all entries.

I really just don't know where to start on trouble shooting this.

Thanks again for your help
Steph
Jun 11 '10 #7
NeoPa
32,557 Recognized Expert Moderator MVP
Debugging in VBA may be of some help.

While debugging, it is often helpful to break down the code from a single line including multiple functions into multiple lines that work out and save each intermediate value.
Jun 11 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1558
by: dave | last post by:
I have one auto number field in one table in sql server 2000. I'm inserting new record using insert statement and am not giving any value for that field as its auto number. On the very next...
1
2560
by: Ken | last post by:
Need help on the Auto Number or Identity Seed on the Oracle Database I got an Access database that need to be converted to Oracle 9i. Somehow the Trigger we created to simulate the "AUTO NUMBER"...
2
3753
by: Irwinsp | last post by:
Hi All, I have a form with an auto number field displayed. The field looks great except when the user is entering a new record. The field then has the text "auto number" in it. Is there a...
5
4523
by: Geoff Cayzer | last post by:
At http://www.blueclaw-db.com/tips_tricks.htm I came across a section which is included below and was hoping for some comment on the article. -------------- Almost never use this auto-number...
16
20442
by: John Baker | last post by:
Hi: I know this is a strange question, but I have inherited a system where files are copied and records re auto numbered (as an index field) )frequently, and I am wondering how high the number...
2
2966
by: Mike N. | last post by:
Hello- I have a database that uses an auto number field type that goes out of sync periodically. My customer gets a "cannot add record, number already in use" error message. I dump the records...
4
10220
by: Shahar | last post by:
Hi I need to get a field name 'ID'(that is an auto-number field) right after I add a new row to table, it's work like that: myCommand.ExecuteNonQuery(); myCommand.CommandText = "SELECT...
13
4728
by: S.Dickson | last post by:
I had an access database that i use as an ordering system. I have a form for entering customer details. When i add a new customer on the form the customer number is an auto number that appears when...
26
2176
by: Scotter | last post by:
Ok, I have 3 tables, one with a customer ID(PK) number and info about the customer(customer table). Another table with an order number(PK), with payment info and such, bieng linked by the customer...
3
2165
by: Wayne L | last post by:
Ok now everyone has mentioned not to use auto number if it means anything to the user. My application uses the auto number for exporting only. I append the mastertbl column with my starting number of...
0
7321
Oralloy
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,...
0
7377
jinu1996
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...
1
7034
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
7488
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
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1544
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.