Hi Fizio
Truly i have would like to cek for every entered data, in case the entered data has present at the table i want to give a message box, this is my complete code,
or may be you have efficient way for it.
Private Sub contro_id_BeforeUpdate(Cancel As Integer)
'Dim dbs As Database, rst As DAO.Recordset
'Set dbs = CurrentDb
Dim dbs As Database, rst As DAO.Recordset
Set dbs = CurrentDb
set rst=dbs.OpenRecordset ("SELECT bincard.contro_id FROM bincard WHERE (((bincard.contro_id)= " & me.contro_id & ")))"
if If IsNull(rst) = false Then
Else
'MsgBox "this document number is already in use, please use another number", vbExclamation
'DoCmd.CancelEvent
'End If
If Dcount("[contro_id]", "bincard", "[contro_id] = " & me.contro_id) > 0 then
MsgBox "this document number is already in use, please use another number", vbExclamation
cancel = true
end if
If contro_id is text then;
Code:
If Dcount("[contro_id]", "bincard", "[contro_id] = '" & me.contro_id) & "'" > 0 then
MsgBox "this document number is already in use, please use another number", vbExclamation
cancel = true
end if
it maybe because contro_id is a text field. I automatically assumend it would be an long integer autonumber
If Dcount("[contro_id]", "bincard", "[contro_id] = '" & me.contro_id & "'") > 0 then
MsgBox "this document number is already in use, please use another number", vbExclamation
cancel = true
end if
Hi Fizio
Thanks very much about your quick solution, it has functioned as required.
If you don't mind i want to ask about the following code, why when i using this code, there is a message about data type mismatch ?
Private Sub contro_id_BeforeUpdate(Cancel As Integer)
Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset("SELECT contro_id from bincard where [contro_id]= '" & Me.contro_id) & "'"
If rst.BOF And rst.EOF Then
Else
MsgBox "this document number is already in use, please use another number", vbExclamation
DoCmd.CancelEvent
End If