Run time error 2147352567

G

Guest

I'm getting the follow explanation for my run time error and do not know what
is causing it. I use the same code in different forms and it works there but
not with the particular form in question.

Here is the explanation I receive:

"The macro or function set to the BeforeUpdate or Validation Rule property
for this field is preventing Database Application from saving the data in the
field.

Note: "Database Application" is the name of the Access program/application
I have designed. I also don't believe there are any validation rules on the
field for which I recieve this error message.

The code I have in the "BeforeUpdate" event for this field is as follows:

Private Sub PrimaryContact_AfterUpdate()

If DMax("CountPrimaryContacts", "qryCountPrimaryBillingContacts") > 0 Then
MsgBox "A Primary Contact has already been established for this
Billing Entity."
Me.PrimaryContact = no
Exit Sub


Else


DoCmd.SetWarnings False
DoCmd.GoToControl "PrimaryContact"
DoCmd.SetWarnings True

End If
End Sub

What the above does is runs a query to determine if there is already a
primary contact setup for a vendor. If there is a primary contact the count
will be greater than zero (0) and we want to reset the "PrimaryContract"
field to "No". If the PrimaryContact field is zero, then we want to go back
to PrimaryContact field so it can be set to "yes" if so desired.

Sorry for the explanation. I sure if you can help me this is very simple
for you.
 
G

Guest

Change: Me.PrimaryContact = no to Cancel = True

You cannot change a field value in the BeforeUpdate event if it has already
been changed (Dirty).

Many people will tell you that this is a good event for assigning values to
fields but I don't use it for that very reason. It works fine for hidden
fields that are not modified by any automation, such as a time stamp.

Steve
 
G

Guest

Unfortunately, I must still be misunderstanding something here or something
else is affecting it. I changed the line to:

Me.PrimaryContact = Cancel

I also tried

Me.PrimaryContact = Cancel = True

I'm still get the same error message.
 
G

Guest

Sorry, I read your post stating the code was in the BeforeUpdate event but
the example code you supplied is in fact the AfterUpdate event...which is it?

What is the data type of the PrimaryContact field?

Is it PrimaryContact or PrimaryContract, you have mentioned both...

Steve
 
G

Guest

My entire problem was becasue I was trying to do this "beforeupdate". Thank
you for pointing this out. It now works.

The other issue was a typo, it should have be primarycontact not
primarycontract.

thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top