Yes or No confirmation at field level

sohailcdc

Registered User.
Local time
Today, 06:49
Joined
Sep 25, 2012
Messages
55
Hello Guru's of Access again i need your expert guidance

I am just trying to learn (during my free time)
My training table consist of 3 fields and using unbound form

1st field custid (text field)
This can't be NIL or Can't duplicate

What I am looking for learning point of view (duel check at same field with different behaviour)

If record is duplicate "Popup message" and curser move back to same field
If field is empty "popup message" Do you want to continue, If yes, move back to field if NO, close form

Therefore, on Before Update event I wrote the following (which was previous help-out by one of Access Guru (thank you again)

Private sub txtcid_beforeupdate (cancel as Integer)
If Dcount("[custid]", "[customerdetails]", "[custid]='" & me.txtcid & "'") > 0 Then
MsgBox "Customer ID already Exists !!!!"
Cancel = True
Me.Txtcid.Undo
End if
(above statement works perfectly (thanks to Access Guru)
------------
If me.txtcid = "" then
If MsgBox ("Message", vbQuestion + vbYesNo, "Test") = vbYes Then
Cancel = True
Me.txtcid.undo
else
docmd.close
end if
end if
end sub

Just a quick update "I tried to used YES or NO option in Exit event too, but no success

eagerly waiting for expert and learning guidance
 
Code:
    Dim Response
    If Me.txtcid = "" Then
      Response = MsgBox("Message", vbQuestion + vbYesNo, "Test")
      If Response = vbYes Then
        Cancel = True
        Me.txtcid.Undo
      Else
        DoCmd.Close
      End If
    End If
Sometimes it pays to consult the help file, than to sit and wait for a reply in a forum. :)
Stand on the word you want to search help for and press "F1".
 
HI JHB

Thanks for response, but it seem I am still missing some controls, as when i press tab or press enter button to exit the field (Yes or No confirmation not working)

The input mask of the txtcid (text field) = >CCCCCCCCCC;;
(I am not sure if input mask making some problem, but i am using this to control the length of field)

here is updated code

Private sub txtcid_beforeupdate(Cancel As Integer)
If Dcount("[custid]", "[customerdetails]", "[custid]='" & me.txtcid & "'") > 0 then
MsgBox "Customer ID already Exists !!!!"
cancel = True
Me.txtcid.undo
end if
Dim response
if me.txtcid = "" then
response = Msgbox ("Message", vbquestion + vbYesNo, "Test")
if response = vbYes then
cancel = true
me.txtcid.undo
else
docmd.close
end if
end if
End sub
 
If you only go into the txtcid control and press tab or press enter button there is nothing to update, then the beforeupdate event isn't getting fired.
Then you have to place the code in the exit event for the control and you have to check for Me.txtcid=null.
Code:
If IsNull(Me.txtcid) Or Me.txtcid = "" Then
If you want to check if all controls are filled out before save, then you have to check it on the form level.
 
Sorry for late reply, I was quite busy with my life routine
 

Users who are viewing this thread

Back
Top Bottom