F
Fadi
Hi
I'll try to explain my problem as simple as possible
I have to fields IDField, TypeField
Its ok for me if the record duplicated if the TypeField=1
But the duplicating is not ok if the TypeField=2
For example these values is ok
IDField TypeField
================
1 1
1 2
1 2
2 1
2 2
2 2
2 2
and these not
IDField TypeField
================
1 1
1 1
I used this code on the form but it's worked with the new records
But its give me an error when I try to edit an existing record
Private Sub Form_BeforeUpdate(Cancel As Integer)
Set rs = CurrentDb.OpenRecordset("Select IDField, TypeField From MyTable
Where (((IDField)=" & IDFieldTxt.Value & ") And ((TypeField)=" &
TypeFieldTxt.Value & "))")
If (Not rs.EOF) And TypeFieldTxt.Value = 1 Then
Cancel = 1
MsgBox "Record Exist", vbOKOnly + vbCritical
ElseIf (Not rs.EOF) And TypeFieldTxt.Value = 2 Then
s = MsgBox("Record Exist, Do you want to save this record as its",
vbYesNo + vbQuestion)
If s = vbNo Then
Cancel = 1
MsgBox "Record NOT saved", vbOKOnly + vbCritical, "Save Error"
End If
End If
End Sub
what i am missing here
Thanks in advance
Fadi
I'll try to explain my problem as simple as possible
I have to fields IDField, TypeField
Its ok for me if the record duplicated if the TypeField=1
But the duplicating is not ok if the TypeField=2
For example these values is ok
IDField TypeField
================
1 1
1 2
1 2
2 1
2 2
2 2
2 2
and these not
IDField TypeField
================
1 1
1 1
I used this code on the form but it's worked with the new records
But its give me an error when I try to edit an existing record
Private Sub Form_BeforeUpdate(Cancel As Integer)
Set rs = CurrentDb.OpenRecordset("Select IDField, TypeField From MyTable
Where (((IDField)=" & IDFieldTxt.Value & ") And ((TypeField)=" &
TypeFieldTxt.Value & "))")
If (Not rs.EOF) And TypeFieldTxt.Value = 1 Then
Cancel = 1
MsgBox "Record Exist", vbOKOnly + vbCritical
ElseIf (Not rs.EOF) And TypeFieldTxt.Value = 2 Then
s = MsgBox("Record Exist, Do you want to save this record as its",
vbYesNo + vbQuestion)
If s = vbNo Then
Cancel = 1
MsgBox "Record NOT saved", vbOKOnly + vbCritical, "Save Error"
End If
End If
End Sub
what i am missing here
Thanks in advance
Fadi