Hi All - thanks for taking an interest!
I have a unique key that I am using as the backbone to a db I'm working on. It is composed of 3 different pieces that make a unique idea (I wanted to go with Autonumber but this is the code they have used in the past so we are sticking with it) The ID looks like this:
ALG03001
where there are 3 parts:
(1) - the location - 3 capital letters: ALG
(2) - the fiscal year - 2 digits: 03
(3) - a sequential number - 3 digit: 001, 002, 003, etc...
I have a form set up so the user can build a new ID through combo box selection so.... I have the location and fiscal year combo boxes all set and in code I add the two together (like ALG03 ) But what I need to do is get the next sequential number so that the key is unique. I have been playing around with the DMax function but I cannot get it to work. This what I have on the button click to submit the ID so far:
But the DMax function wont work...? Basically, I need to look at all of the IDs in the db that match the unit (ALG) and the Fiscal Year(03) and then go one higher than the previous entry and have it in the correct format (000). Am I attempting this wrong? should I use something else like a recordset? I have been starting at this for so long I am really confusing myself
Any all help is appreciated!
Kev
I have a unique key that I am using as the backbone to a db I'm working on. It is composed of 3 different pieces that make a unique idea (I wanted to go with Autonumber but this is the code they have used in the past so we are sticking with it) The ID looks like this:
ALG03001
where there are 3 parts:
(1) - the location - 3 capital letters: ALG
(2) - the fiscal year - 2 digits: 03
(3) - a sequential number - 3 digit: 001, 002, 003, etc...
I have a form set up so the user can build a new ID through combo box selection so.... I have the location and fiscal year combo boxes all set and in code I add the two together (like ALG03 ) But what I need to do is get the next sequential number so that the key is unique. I have been playing around with the DMax function but I cannot get it to work. This what I have on the button click to submit the ID so far:
Private Sub cmdSubmitWIP_Click()
On Error GoTo err_desc_click
Dim strUnitYear As String
If IsNull(Me.cmboUnitCodes) Or IsNull(Me.cmboYear) Then
MsgBox "Incomplete Submission ID", vbOKOnly, "Add New Submission ID Cancelled"
ElseIf MsgBox("Confirm add new Submission ID", vbOKCancel, "Confirm Add New WIP") = vbOK Then
strUnitYear = Me.cmboUnitCodes & Me.cmboYear
DMax("[SubmissionID]","dbo_WIP_Main", "[SubmissionID]= 'strUnitYear'")
Else
Me.cmboUnitCodes = Null
Me.cmboYear = Null
Me.cmboUnitCodes.SetFocus
End If
err_desc_exit:
Exit Sub
err_desc_click:
MsgBox Err.Number & Err.Description
Resume err_desc_exit
End Sub
But the DMax function wont work...? Basically, I need to look at all of the IDs in the db that match the unit (ALG) and the Fiscal Year(03) and then go one higher than the previous entry and have it in the correct format (000). Am I attempting this wrong? should I use something else like a recordset? I have been starting at this for so long I am really confusing myself
Any all help is appreciated!
Kev