bassman197
Registered User.
- Local time
- Today, 12:54
- Joined
- Sep 18, 2007
- Messages
- 35
The following code is meant to find out if the contract number the user is trying to enter already exists in the table overdues in the field [Contract Num]. I've gotten it to the point where it doesn't return an error, but it doesn't do what I'd hoped either - it simply opens the error message form no matter what number you enter, existing or not. Since contract numbers contain a dash, the field [Contract Num] in the table is a TEXT field. The DCount line is causing the problem; the field and table parts maybe OK, but the criteria part is a mess!
Code:
[SIZE=2]
Private Sub Contract_Num_BeforeUpdate(Cancel As Integer)
'If the contract number does not yet exist
If IsNull(DCount("[Contract Num]", "overdues", "[Contract Num]=forms![overdues1 new contract].[Contract Num].value")) Then
'then allow the entry
Exit Sub
Else
'open error message
DoCmd.OpenForm "Contract Number Duplicate"
'and undo users input
Cancel = True
Me.[Contract Num].Undo
End If
End Sub
[/SIZE]