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 -
Private Sub Region_AfterUpdate() 'autonumber
-
If Me.NewRecord Then
-
Me.Code = Me.Region & "" & "MN" & Nz(DMax("val(Right('[fieldnamedcode]',Len('[fieldnamedcode]')-4))", "[Support Detail]") + 1, "0000")
-
End If
-
End Sub
-
I've also tried -
Private Sub Region_AfterUpdate() 'autonumber
-
If Me.NewRecord Then
-
Me.Code = Me.Region & "" & "MN" & Nz(DMax("val(Right('[fieldnamedcode]',4))", "[Support Detail]") + 1, "0000")
-
End If
-
End Sub
-
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
7 3399
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: -
Me.Code = Me.Region & "MN" & me.CodeValue
-
I eliminated the extra quote marks as they were not doing anything.
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 : - Private Sub Region_AfterUpdate() 'autonumber
-
If Me.NewRecord Then
-
Me.Code = Me.Region & "MN" & _
-
Format(Nz(DMax("Right([code],4)", _
-
"[Support Detail]"), 0) + 1, "0000")
-
End If
-
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.
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
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 : - Private Sub Region_AfterUpdate() 'autonumber
-
If Me.NewRecord Then
-
Me.Code = Me.Region & "MN" & Format(Val(Nz( _
-
DMax("Right([code],4)", _
-
"[Support Detail]"), "0")) + 1, "0000")
-
End If
-
End Sub
NeoPa 32,557
Recognized Expert Moderator MVP
For numbering sequentially by Region try : - Private Sub Region_AfterUpdate() 'autonumber
-
If Me.NewRecord Then
-
Me.Code = Me.Region & "MN" & Format(Val(Nz( _
-
DMax("Right([code],4)", _
-
"[Support Detail]", _
-
"[code] Like '" & Me.Region & "MN????'"), "0")) + 1, "0000")
-
End If
-
End Sub
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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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"...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 ...
|
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...
| |