Ok guys, I have another problem...last one for today. When i click save on my form, it will check for nulls or 0 entries on 3 text boxes... I'm using fruit in this example for arguments sake and it works ok... I'd like to introduce testing of duplicate entries somewhere in this code, so on each textbox, i've added an afterupdate routine to test for duplicate entries within my table (see below). This seems to work on a one off basis but wont work say if i try and edit apples whilst stuck between pears and grapes!!! What is the best way to test for duplicates in this instance??
Private Sub SaveRecord_Click()
If IsNull(apples) Or apples = 0 Then
MsgBox "Please Enter Number of apples", vbInformation, ""
apples.SetFocus
ElseIf IsNull(pears) Or pears = 0 Then
MsgBox "Please Enter number of pears", vbInformation, ""
pears.SetFocus
ElseIf IsNull(grapes) Or grapes = 0 Then
MsgBox "Please Enter number of grapes", vbInformation, ""
grapes.SetFocus
Else
[myapples] = apples
[mypears] = pears
[mygrapes] = grapes
end if
Private Sub apples_AfterUpdate()
Dim testfruit As String
testfruit = Nz(DLookup("[myapples]", "RECORDS", "[myapples]='" & Me.apples & "'"))
If IsNull(testfruit) Then
Else
MsgBox "A quantity of this fruit already exists on database", vbInformation, ""
apples.SetFocus
exit
End If
<Same afterupdate routines as above for pears and grapes>
Private Sub SaveRecord_Click()
If IsNull(apples) Or apples = 0 Then
MsgBox "Please Enter Number of apples", vbInformation, ""
apples.SetFocus
ElseIf IsNull(pears) Or pears = 0 Then
MsgBox "Please Enter number of pears", vbInformation, ""
pears.SetFocus
ElseIf IsNull(grapes) Or grapes = 0 Then
MsgBox "Please Enter number of grapes", vbInformation, ""
grapes.SetFocus
Else
[myapples] = apples
[mypears] = pears
[mygrapes] = grapes
end if
Private Sub apples_AfterUpdate()
Dim testfruit As String
testfruit = Nz(DLookup("[myapples]", "RECORDS", "[myapples]='" & Me.apples & "'"))
If IsNull(testfruit) Then
Else
MsgBox "A quantity of this fruit already exists on database", vbInformation, ""
apples.SetFocus
exit
End If
<Same afterupdate routines as above for pears and grapes>