By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,400 Members | 981 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,400 IT Pros & Developers. It's quick & easy.

Stop user adding record to subform

P: n/a
DD
Hi i have borrowed this code from Nothwind
used in the subform ProductID..it comes up with an error on RunCommand
acCmdUndo

Can anyone advise or give me a better way
DD

Private Sub Form_Error(DataErr As Integer, Response As Integer)

' Errors can occur here if the user has not already selected a
customer for
' this order on the main form. If there is an error and Orders!BillTo
is Null
' inform the user and cancel the entry made in the subform.
If DataErr > 0 Then
If IsNull(Me.Parent!CustomerID) Then
MsgBox "Select a Customer to bill to before entering order
details info."
RunCommand acCmdUndo
Me.Parent!CustomerID.SetFocus
Response = acDataErrContinue
Else
Response = acDataErrDisplay
End If
End If

End Sub
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
DD wrote:
Hi i have borrowed this code from Nothwind
used in the subform ProductID..it comes up with an error on RunCommand
acCmdUndo

Can anyone advise or give me a better way
DD

Private Sub Form_Error(DataErr As Integer, Response As Integer)

' Errors can occur here if the user has not already selected a
customer for
' this order on the main form. If there is an error and Orders!BillTo
is Null
' inform the user and cancel the entry made in the subform.
If DataErr > 0 Then
If IsNull(Me.Parent!CustomerID) Then
MsgBox "Select a Customer to bill to before entering order
details info."
RunCommand acCmdUndo
Me.Parent!CustomerID.SetFocus
Response = acDataErrContinue
Else
Response = acDataErrDisplay
End If
End If

End Sub

Code like that I would put into BeforeInsert, e.g.

Sub Form_BeforeInsert(Cancel As Integer)
If IsNull(me.Parent!CustomerID) Then
Msgbox "Oi, User... No!"
Me.Parent!CustomerID.SetFocus
Cancel = True
End If
End Sub

--
But why is the Rum gone?
Nov 12 '05 #2

P: n/a
"Trevor Best" <nospam@localhost> wrote in message
news:40***********************@auth.uk.news.easyne t.net...
Sub Form_BeforeInsert(Cancel As Integer)
If IsNull(me.Parent!CustomerID) Then
Msgbox "Oi, User... No!"


LOL! We need more messages like that.

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.