BefreUpdate set to null error 2115

J

jlute

With my pathetic skills I've concocted the following BeforeUpdate
event. It works except for the set to null. This generates error 2115:
"The macro or function...is preventing Access from saving the data in
the field."

Well, I don't want to save the data given the If condition! Anyone
have an idea how I can re-write this?

Thanks in advance!!!

Private Sub Weight_BeforeUpdate(Cancel As Integer)
If Len(Me!Weight & vbNullString) > 0 Then
If Len(Forms!frmPKPartitions!sfrmPKPNPhysicalAttributes.Form!
sfrmPKPNsLayoutDetails.Form!Weight & vbNullString) > 0 Then
Beep
If MsgBox("Partition can't have a Physical Attribute Weight and
a Layout Details Weight!" & vbCrLf & _
"Click OK to set to NULL.", vbOKOnly + _
vbQuestion) = vbOK Then
Me!Weight = Null
Cancel = False
DoCmd.GoToControl "WeightUOM"
End If
End If
End If

End Sub
 
K

Klatuu

First, to cancel the event, you use Cancel = True
Here is how I would do it:

Private Sub Weight_BeforeUpdate(Cancel As Integer)
If Len(Me!Weight & vbNullString) > 0 And _

Len(Forms!frmPKPartitions!sfrmPKPNPhysicalAttributes.Form!sfrmPKPNsLayoutDetails.Form!Weight & vbNullString) > 0 Then
Beep
If MsgBox("Partition can't have a Physical Attribute Weight and a
Layout Details Weight!" & vbCrLf & "Click OK to set to NULL.", vbOKOnly +
vbQuestion) = vbOK Then
Me!Weight.Undo
Cancel = True
Me!WeightUOM.SetFocus
End If
End If

End Sub
 
J

jlute

Ah...that makes sense. Thanks, Dave!

First, to cancel the event, you use Cancel = True
Here is how I would do it:

Private Sub Weight_BeforeUpdate(Cancel As Integer)
    If Len(Me!Weight & vbNullString) > 0 And _

Len(Forms!frmPKPartitions!sfrmPKPNPhysicalAttributes.Form!sfrmPKPNsLayoutDe­tails.Form!Weight & vbNullString) > 0 Then
        Beep
       If MsgBox("Partition can't have a Physical Attribute Weight and a
Layout Details Weight!" & vbCrLf & "Click OK to set to NULL.", vbOKOnly +
vbQuestion) = vbOK Then
          Me!Weight.Undo
          Cancel = True
          Me!WeightUOM.SetFocus
       End If
    End If

End Sub

--
Dave Hargis, Microsoft Access MVP







- Show quoted text -
 
G

Guest

no thanks iam so ok if u got any boys from 16-18 let them right

Hi, Arvin.

Nope. That's the weird thing!
 

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

OnExit driving me crazy 3
Run-Time Error 2115 1
<= 0 11
simplified AfterUpdate? 1
Run-time error '2115' 1
Run-time error '2115' 3
Null Field to Interupt Closing 4
Validation Dummy 7

Top