Alhakeem1977
Registered User.
- Local time
- Today, 23:45
- Joined
- Jun 24, 2017
- Messages
- 308
Hi All,
How to avoid generating sequential ID if before update event took place?
below is my codes in the Before update event and Save button:
In the save button:
I did my best to avoid getting the sequential Id [Seq] if a condition in the before update event took place.
By the way, the database is split (Multi-users environment) many users at the same time could use the data entry form, the sequential ID is the most important field in my project.
Thanks a lot in advance!
How to avoid generating sequential ID if before update event took place?
below is my codes in the Before update event and Save button:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo ErrorHandler
Dim strLinkCriteria As String
Dim strMessage As String
If Len(Trim(Me!cboRecDept & vbNullString)) = 0 Then
strMessage = strMessage & " You must provide the Receiver's Department!" & vbCrLf
Me.cboRecDept.SetFocus
End If
If Len(Trim(Me!cboDescription & vbNullString)) = 0 Then
strMessage = strMessage & " You must provide the Description!" & vbCrLf
Me.cboDescription.SetFocus
End If
If Len(strMessage) > 0 Then
MsgBox strMessage, vbCritical
Cancel = True
Me.Undo
Else
Me.cmdSave.SetFocus
End If
Cleanup:
Exit Sub
ErrorHandler:
MsgBox Err.Number & ": " & Err.Description
Beep
MsgBox "Sorry, there was an error occurred, please revert your record !.", vbOKOnly, "Error"
Resume Cleanup
End Sub
In the save button:
Code:
Private Sub cmdSave_Click()
On Error GoTo ErrorHandler
Me![PKDes] = Nz(DMax("[PKDes]", "tblDeptReg"), 0) + 1
Me![Seq] = Nz(DMax("[Seq]", "tblDeptReg", "Year([SentOn]) = " & Year(Me.[SentOn]) & " AND " & _
"[SentDept] = " & Me.txtDeptID & ""), 0) + 1
Me.Ref = [txtDeptShName] & Format([SentOn], "yy") & Format([Seq], "0000")
DoCmd.RunCommand acCmdSave
Me.cmdSave.Enabled = False
Me.txtNo.Requery
Beep
Me.cmdNew.SetFocus
Cleanup:
Exit Sub
ErrorHandler:
MsgBox Err.Number & ": " & Err.Description
Beep
MsgBox "Sorry, there was an error occurred, please revert your record !.", vbOKOnly, "Error"
Resume Cleanup
End Sub
I did my best to avoid getting the sequential Id [Seq] if a condition in the before update event took place.
By the way, the database is split (Multi-users environment) many users at the same time could use the data entry form, the sequential ID is the most important field in my project.
Thanks a lot in advance!