Alhakeem1977
Registered User.
- Local time
- Today, 11:43
- Joined
- Jun 24, 2017
- Messages
- 308
Need your help to fix the below code I got Compile error Else without if.
Actually, the code prevents any duplicate entry and Spill Checker too.
I don't know how to fix it.
Thanks in advance
Actually, the code prevents any duplicate entry and Spill Checker too.
I don't know how to fix it.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo ErrorHandler
Dim strLinkCriteria As String
strLinkCriteria = "[DocumentName] = '" & Me!DocumentName & "'"
If DCount("*", "tblDocumentName", strLinkCriteria) > 0 Then
MsgBox "This document Name already exists in the database.", vbCritical, "Duplicate Entry"
Cancel = True
Me.Undo
Else
With Me![DocumentName]
If Len(.Value) > 0 Then
DoCmd.SetWarnings False
.SetFocus
.SelStart = 1
.SelLength = Len(.Value)
DoCmd.RunCommand acCmdSpelling
End If
End With
Cancel = True
End If
Else
Me.DocID = Nz(DMax("DocID", "tblDocumentName"), 0) + 1
End If
End If
Cleanup:
Exit Sub
ErrorHandler:
MsgBox Err.Number & ": " & Err.Description
Resume Cleanup
End Sub
Thanks in advance