Why VBA DCount statement not editing the table data

I have the following code in an onclick event of a command button on a form but if the record already exists (PetID), it is not editing the record.  Instead, it is creating a new record.  ????

Dim RS As DAO.Recordset
Set RS = CurrentDb.OpenRecordset("tblAuthorizationFormData")
If DCount("*", "tblAuthorizationFormData", "PetID = " & Me.txtPetID) > 0 Then
MsgBox "This request for pickup already exists and will be edited if you have made changes."
RS.Edit
RS!PetID = Me.txtPetID
Etc., etc.
RS.Update
Else
MsgBox "This appears to be a new pickup request which does not already exist in the program.  A new pickup request is being created."
RS.AddNew
RS!ReqForPickUpID = Me.txtReqForPickUpID
RS!PetName = Me.txtPetName
Etc., etc.
RS.Update
MsgBox "The new pickup request has been created in the Authorization Form Data table."
End If

Open in new window

SteveL13Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:
If DCount("*", "tblAuthorizationFormData", "PetID = " & Me.txtPetID) > 0 Then
MsgBox "This request for pickup already exists and will be edited if you have made changes."

'Now find the record with the  'PetID = " & Me.txtPetID
with RS
         .findfirst "[PetID] = " & Me.txtPetID
         me.bookmark=.bookmark
         
          .edit
          !FIELD1=etc
          etc
          .update
end with
       
         
Else
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rey Obrero (Capricorn1)Commented:
or Open another recordset for edting

dim rs1 as dao.recordset

If DCount("*", "tblAuthorizationFormData", "PetID = " & Me.txtPetID) > 0 Then
MsgBox "This request for pickup already exists and will be edited if you have made changes."
set rs1=currentdb.openrecordset("select * from tblAuthorizationFormData where PetID = " & Me.txtPetID)

rs1.edit
etc..
rs1.update

rs1.close

else
0
SteveL13Author Commented:
Worked!!!  Thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.