473,473 Members | 2,131 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using DMax to assign a unique request number in a subform

4 New Member
My database tracks submission requests from customers. I have a parent form (frmSubmitterLibrary) and a subform (frmSubmissionRequest) which is based on a table (SubmissionTable). The ClientID links the two forms. I would like the "MyCounter" field in the SubmissionTable to sequentially assign a number to each submission that is specific to the customer. EX: CustomerA submits 3 requests; CustomerB submits 2 requests; and CustomerC submits 5 requests all on the same day at different times. I would like the SubID to look like: CA-1, CA-2, CA-3, CB-1, CB-2, CC-1, CC-2...CC-5.

Following is the code that I am using:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeInsert(Cancel As Integer)
  2.     MyCounter = Nz(DMax("MyCounter", "SubmissionTable", "ClientID=" & Forms!frmSubmitterLibrary!tbxClientID)) + 1
  3. End Sub
I am missing some crucial code, but I can't figure out on my own. Any help would be very much appreciated.
Jan 14 '10 #1
10 3262
nico5038
3,080 Recognized Expert Specialist
Did you try Me.MyCounter as I assume the field is named MyCounter and resides on your form with that name.

Nic;o)
Jan 14 '10 #2
NeoPa
32,556 Recognized Expert Moderator MVP
@wilhelmmt
Indeed, and some logic, but let's see if we can't fill in the gaps a little. BTW, the concept is absolutely the right way to go about this problem.

Let me first say that it's generally a good idea to use a single term for an item when talking technically. Customer and Client are synonymous I assume. I'm working on that basis.

The result of your DMax() function call, when not Null, will be a string value including both the Client identification prefix, as well as the numerical part. You are currently treating this as a purely numerical value it seems. You need to separate and extract the numerical part as well as the Client prefix (Mid()), Increment the numerical value, Add it back to the same Client prefix.
Jan 14 '10 #3
wilhelmmt
4 New Member
NeoPa,
Thank you for pointing out the need to use a single term, and yes Customer and Client are synonymous.
I am having difficulty using the Clidnt prefix (Mid()) that you suggested. Could you please show me how it would be used in code?
Thanks again for your help.
Maura
Jan 26 '10 #4
NeoPa
32,556 Recognized Expert Moderator MVP
Assuming that the form the code is in, is actually called frmSubmitterLibrary, that tbxClientID contains the client code without the "-" and that each Client code is 2 characters exactly then :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeInsert(Cancel As Integer)
  2.     MyCounter = Me.tbxclientID & "-" &  _
  3.                 Val(Mid(Nz(DMax("MyCounter", _ 
  4.                                 "SubmissionTable", _
  5.                                 "ClientID='" & Me.tbxClientID) & "-*'", _
  6.                            "XX-0"), 4, 9)) + 1
  7. End Sub
Jan 27 '10 #5
wilhelmmt
4 New Member
The code is actually in a subform called frmSubmissionRequest. The parent form is called frmSubmitterLibrary.

The textbox tbxClientID is located on the subform, with the Control Source of =DLookUp("[ClientID]","SubmitterLib","[ClientID] = Forms![frmSubmitterLibrary]![ClientID]").

Each Client code is exactly 3 characters, not 2, and each Client on the Parent form will have multiple submissions entered on the subform.

Does this change the code you offered?
Thanks again for your help.
Jan 27 '10 #6
NeoPa
32,556 Recognized Expert Moderator MVP
@wilhelmmt
That makes your original code a little weird, but that's probably a simple misunderstanding I guess.
@wilhelmmt
This needs some further explanation. Probably some examples that match what you are saying would help. Of tbxClientID values as well as the MyCounter values please. An explanation of why the parent form seems to be dealing with numeric ClientIDs while the subform, and your explanations so far, deal only in strings.
@wilhelmmt
Yes, but not fundamentally. Unless the whole ClientID thing is stranger than I anticipate. I await your response to know fully.
Jan 27 '10 #7
wilhelmmt
4 New Member
Thanks so much for your patience.

The ClientID is simply 3 characters representing the client's full name, ex: AEC would be the ClientID for "Ann E. Customer" and MTW would be the ClientID for "Maura T. Wilhelm".

MyCounter is the number of submissions a specific ClientID has made to the database. Ex: AEC has made 2 submissions thus far, and is about to make a third. MTW has made 4 submissions thus far, and will make a 5th.
The SubmissionTable reads as follows:
Expand|Select|Wrap|Line Numbers
  1. SubID  ClientID  MyCounter
  2. AEC-1     AEC        1
  3. MTW-1     MTW        1
  4. MTW-2     MTW        2
  5. AEC-2     AEC        2
  6. MTW-3     MTW        3
  7. MTW-4     MTW        4
When AEC opens the submission form, the code should look at the table and see what the highest MyCounter number is for the ClientID=AEC (which is 2) and add 1 to AEC's MyCounter field, thus writing back to the table:

AEC-3 AEC 3

The SubID is just a combination of the ClientID and that client's MyCounter field.

Please let me know if I have explained things any better.
Jan 28 '10 #8
NeoPa
32,556 Recognized Expert Moderator MVP
You certainly have.

I will look at this later when I have a little time but it's fundamentally quite straightforward.
Jan 28 '10 #9
nico5038
3,080 Recognized Expert Specialist
From a normalization point of view the SubID shouldn´t be stored in a table as it´s deductable. I would use on the form an unbound field that´s filled with
Expand|Select|Wrap|Line Numbers
  1. =ClientID & "-" & MyCounter
This formula can also be used in a query.

Nic;o)
Jan 28 '10 #10
NeoPa
32,556 Recognized Expert Moderator MVP
I have to say I agree with Nico.

At the moment though, there are two ways to do this. I'll include both in case you decide to normalise your database (recommended) and lose one of the sets of fields in the process.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeInsert(Cancel As Integer)
  2.     MyCounter = Nz(DMax("[MyCounter]", _ 
  3.                         "[SubmissionTable]", _
  4.                         "[ClientID]='" & Me.tbxClientID) & "'"), 0) + 1
  5. End Sub
If only [SubID] left in the record (after Normalisation update), and assuming all else equal, then :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeInsert(Cancel As Integer)
  2.     MyCounter = Val(Mid(Nz(DMax("[SubID]", _ 
  3.                                 "[SubmissionTable]", _
  4.                                 "[SubID] Like '" & Me.tbxClientID) & "-*'", _
  5.                            "XXX-0"), 5, 9)) + 1
  6. End Sub
NB. Previous SQL code (post #5) was incorrect. Line #5 should have used Like not =.
Jan 29 '10 #11

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

Similar topics

0
by: amywolfie | last post by:
Hi all: I have a subform called sfrmFootnotes linked to main Form frmFeeInput (the latter based on tblFees). tlkpFootnotes contains the PK for Footnotes. tjnCode_Footnotes is a join table...
4
by: lukeargent | last post by:
Hi All, I have come across some rather weird error that I can only assume is something to do with my ADP file connecting to SQL Server 2000. I'm using Access XP as my front end. In simple...
3
by: peddie | last post by:
Hi, I have a table that contains two key fields. I would like to assign the auto number for the secondary key field by starting from 1. For example primary Key id second Key Id...
2
by: dskillingstad | last post by:
I'm trying to assign a custom value to a textbox. Here's what I have. I've created a module and "default value" code for a textbox which generates a custom auto-number (yyyy-0000) when a New...
8
by: Jimbo | last post by:
Hello I am currently designing an internal ordering system for IT equipment. I am designing it in ASP.NET (vb) using Visual Studio 2003 and using Microsoft SQL Server I have got the system...
14
by: ml_sauls | last post by:
I've built a system to enter and manage purchase orders. This is in use by >10 clients. Some use it in Access 97, most are in A2k. About half use it through a Citrix implementation. It is...
3
by: emalcolm_FLA | last post by:
Hello and Thanks in advance for any help. I have been tasked with rewriting a christmas assistance database using Access 2003. The old system used pre-assigned case numbers to identify...
2
by: dbstrat | last post by:
Hi. I have 3 tables that I need to display on a master-child form/subform. Think of it as Orders and Order Details. The tables are Orders OrderDetails VendorItems
17
by: Pascal | last post by:
hello everybody ! I get this error 3 times : "The output parameter must be assigned before the control leaves the current method" (dor dMin and dMax) this one 1 time : Use of the parameter 'out'...
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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
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.