Alhakeem1977
Registered User.
- Local time
- Today, 05:28
- Joined
- Jun 24, 2017
- Messages
- 308
Your kind help to make the below code return the result in the message box instead of returning the previous record in the form.
Obviously this part:
Thanks in advance.
Obviously this part:
Me.Recordset.FindFirst strLinkCriteria
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo ErrorHandler
Dim strLinkCriteria As String
Dim strMessage As String
Dim DocID As Integer
If Len(Trim(Me!AccountNo & vbNullString)) = 0 Then
strMessage = strMessage & " You must provide an Account Number!" & vbCrLf
Me.AccountNo.SetFocus
End If
If Len(Trim(Me!DocumentDate & vbNullString)) = 0 Then
strMessage = strMessage & " You must provide a Document Date!" & vbCrLf
Me.DocumentDate.SetFocus
End If
If Len(Trim(Me!DocumentName & vbNullString)) = 0 Then
strMessage = strMessage & " You must provide a DocumentName!" & vbCrLf
Me.DocumentName.SetFocus
End If
If Len(strMessage) > 0 Then
MsgBox strMessage, vbCritical
Cancel = True
' Me.Undo
Else
strLinkCriteria = "[AccountNo] = " & Me!AccountNo & " AND " & _
"[DocumentDate] = " & Format$(Me!DocumentDate, "\#mm\/dd\/yyyy\#") & " AND " & _
"[DocumentName] = " & Me!DocumentName
If DCount("*", "tblFacilityRegister", strLinkCriteria) > 0 Then
Me.img1.Visible = True
MsgBox "This document has already been sent earlier!" & vbCrLf & _
"Press OK to lead you to the previous record." & vbCrLf & _
"Please write the(Doc ID) at the ((back)) top to make sure it's actually matched." & vbCrLf & _
"Ignore the number of records.", vbCritical, "Duplicate Entry"
Cancel = True
Me.Undo
Me.DataEntry = False
Me.AllowEdits = False
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Me.Recordset.FindFirst strLinkCriteria
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Me.New_Record.SetFocus
Me.txtDocsToBeSent.Requery
Else
Me.SeqNo = Nz(DMax("[SeqNo]", "tblFacilityRegister", "Year([SentDate]) = " & Year(Me.[SentDate])), 0) + 1
Me.DocID = Format([SeqNo], "0000") & "/" & Format([SentDate], "yy")
Me.img1.Visible = False
Me.DocID.BackColor = vbRed
Me.Detail.BackColor = vbGreen
Me.New_Record.SetFocus
End If
End If
Cleanup:
Exit Sub
ErrorHandler:
MsgBox Err.Number & ": " & Err.Description
Beep
MsgBox "You must enter a value in one of the following:" & vbCrLf & _
vbCr & "Account Number, DTD or Document Name.", vbOKOnly, "Empty Fields"
Resume Cleanup
End Sub
Thanks in advance.