Hi,
I have a table name ExpenseClaim where it has a field named RefNo to store the Primary ID for each record.
In my form, I has a combo box named cboExpenseCode: -
1) If user select "Company Reimbursed", then the prefix for the Primary ID is P-xxx
2) If user select "Project Reimbursed", then the prefix for the Primary ID is OF-xxx
xxx- represent the incremental id (e.g OF-001 , OF-002 / P-001, P-002) for the different expense code selected.
My code goes here :
But I get a problem here, the if let say the table has OF-001, the first ID value for Project Reimbursed will start with P-002. I want it to begin with P-001.
The DMax will only recognize the maximum value for the number. Can anyone please guide me how to get the output that I want? This should be easy, but I just cannot figure out the solution :(
Thank you very much.
I have a table name ExpenseClaim where it has a field named RefNo to store the Primary ID for each record.
In my form, I has a combo box named cboExpenseCode: -
1) If user select "Company Reimbursed", then the prefix for the Primary ID is P-xxx
2) If user select "Project Reimbursed", then the prefix for the Primary ID is OF-xxx
xxx- represent the incremental id (e.g OF-001 , OF-002 / P-001, P-002) for the different expense code selected.
My code goes here :
Code:
Private Sub cboExpenseCode_AfterUpdate()
If Me.NewRecord And Me.cboExpenseCode.Value = "Project Reimbursed" Then
Dim NextPRefNo As Long
NextPRefNo = Nz(DMax("Right ([RefNo],3)", "ProjectExpenses"), 0) + 1
Me![RefNo] = "P-" & Format(CStr(NextPRefNo), "000")
ElseIf Me.NewRecord And Me.cboExpenseCode.Value = "Company Reimbursed" Then
Dim NextOFRefNo As Long
NextOFRefNo = Nz(DMax("Right ([RefNo],3)", "ProjectExpenses"), 0) + 1
Me![RefNo] = "OF-" & Format(CStr(NextOFRefNo), "000")
End If
End Sub
The DMax will only recognize the maximum value for the number. Can anyone please guide me how to get the output that I want? This should be easy, but I just cannot figure out the solution :(
Thank you very much.
Comment