BefreUpdate set to null error 2115

  • Thread starter Thread starter jlute
  • Start date Start date
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
 
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
 
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 -
 
no thanks iam so ok if u got any boys from 16-18 let them right

Hi, Arvin.

Nope. That's the weird thing!
 
Back
Top