Donna Tunstall
Registered User.
- Local time
- Today, 16:19
- Joined
- Aug 16, 2001
- Messages
- 17
Hi There,
I need to do a check in my database to make sure a duplicate value does not exist and force the user back to that field to re-enter if it does. I have a mainform and a subform and this is my code:
Private Sub PROJNUM_BeforeUpdate(Cancel As Integer)
If (DLookup("[ProjNum]", "tblProjectHeader", "[ProjNum]" = Forms!frmRegistrationForm!PROJNUM) Is Not Null) Then
Beep
MsgBox "The Bizman Number you entered already exists. Enter a unique Bizman Number", vbInformation, "Duplicate Bizman"
Me.PROJNUM.SetFocus
End If
End Sub
In testing when I enter a duplicate ID, the message box shows but the code completely ignores my setfocus command and moves the cursor to the next field anyway AND (which is worse) populates my subform with all the data relating to that duplicate ID.
How can I stop this? If a duplicate is detected I want the whole bus-load to stop and force the user to enter a unique ID. I've been playing with this for a few days now and am at my wits end. Any help would be greatly appreciated.
TIA.
I need to do a check in my database to make sure a duplicate value does not exist and force the user back to that field to re-enter if it does. I have a mainform and a subform and this is my code:
Private Sub PROJNUM_BeforeUpdate(Cancel As Integer)
If (DLookup("[ProjNum]", "tblProjectHeader", "[ProjNum]" = Forms!frmRegistrationForm!PROJNUM) Is Not Null) Then
Beep
MsgBox "The Bizman Number you entered already exists. Enter a unique Bizman Number", vbInformation, "Duplicate Bizman"
Me.PROJNUM.SetFocus
End If
End Sub
In testing when I enter a duplicate ID, the message box shows but the code completely ignores my setfocus command and moves the cursor to the next field anyway AND (which is worse) populates my subform with all the data relating to that duplicate ID.
How can I stop this? If a duplicate is detected I want the whole bus-load to stop and force the user to enter a unique ID. I've been playing with this for a few days now and am at my wits end. Any help would be greatly appreciated.
TIA.