C
CB
Hi everyone,
I’m having some difficulty auto-incrementing a Quote Request number on a
sub-form I’ve created. I’ve searched the newsgroups and haven’t yet found
anything quite like this.
My main form includes contractor information and contract numbers (record
source is a query pulling info from two tables: t_ContractorInfo and
t_ContractSpecifics) and the sub-form is where quote requests will be
entered. CSID is the field that links the main form to the sub-form.
The record source for my sub-form is the table t_QuoteRequests with the
following fields (among others):
QRID – autonum, PK (otherwise meaningless)
QRNum – number (quote request number)
CSID – number (FK – contract specifics ID)
CSID and QRNum are indexed together since I want to prevent duplicate Quote
Request numbers for a given contract.
Overall, the form works fine. What I now need is that when a new quote
request record is added, QRNum increments appropriately by 1 **depending on
the CSID field.**
In other words, I need all contracts to have sequential QRNums all starting
at one. The way things currently stand, QRNum increments the same way the
QRID field does so the QRNums for a given contract are not sequential.
Currently,
QRID QRNum CSID
1 1 1
2 2 1
3 3 4
4 4 1
5 5 3
What I need,
QRID QRNum CSID
1 1 1
2 2 1
3 1 4
4 3 1
5 1 3
The following code is what I currently have in the sub-form’s BeforeInsert
event. FWIW, I originally had this in the sub-form’s BeforeUpdate event (per
what I found on the newsgroups) but the field didn’t seem to populate until
after I left the record.
Private Sub Form_BeforeInsert(Cancel As Integer)
Me![QRNum] = Nz(DMax("[QRNum]", "t_QuoteRequests"), 0) + 1
End Sub
Thanks for any and all assistance!
Warm regards,
Chris
I’m having some difficulty auto-incrementing a Quote Request number on a
sub-form I’ve created. I’ve searched the newsgroups and haven’t yet found
anything quite like this.
My main form includes contractor information and contract numbers (record
source is a query pulling info from two tables: t_ContractorInfo and
t_ContractSpecifics) and the sub-form is where quote requests will be
entered. CSID is the field that links the main form to the sub-form.
The record source for my sub-form is the table t_QuoteRequests with the
following fields (among others):
QRID – autonum, PK (otherwise meaningless)
QRNum – number (quote request number)
CSID – number (FK – contract specifics ID)
CSID and QRNum are indexed together since I want to prevent duplicate Quote
Request numbers for a given contract.
Overall, the form works fine. What I now need is that when a new quote
request record is added, QRNum increments appropriately by 1 **depending on
the CSID field.**
In other words, I need all contracts to have sequential QRNums all starting
at one. The way things currently stand, QRNum increments the same way the
QRID field does so the QRNums for a given contract are not sequential.
Currently,
QRID QRNum CSID
1 1 1
2 2 1
3 3 4
4 4 1
5 5 3
What I need,
QRID QRNum CSID
1 1 1
2 2 1
3 1 4
4 3 1
5 1 3
The following code is what I currently have in the sub-form’s BeforeInsert
event. FWIW, I originally had this in the sub-form’s BeforeUpdate event (per
what I found on the newsgroups) but the field didn’t seem to populate until
after I left the record.
Private Sub Form_BeforeInsert(Cancel As Integer)
Me![QRNum] = Nz(DMax("[QRNum]", "t_QuoteRequests"), 0) + 1
End Sub
Thanks for any and all assistance!
Warm regards,
Chris