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

unload event not working

P: n/a
In my form customers i want to forbid the user to leave the record if
he has not written the CompanyName.To do this, i have put in the unolad
event the following

Private Sub Form_Unload(Cancel As Integer)
If IsNull(Me.TypeID) Then
MsgBox "please enter company !!! "
DoCmd.CancelEvent
End If
End Sub

I also have a button called back with which i return to the main form.
I also have another button called AddIt, with which the new client is entered.
My problem is, that when we open the form with the button AddIt,we can
leave the from with the button Back even no company name is being entered.
In this way i allow the user to leave the form with a blank company name
and in fact my code in the OnOnload event is useless.
May i ask for help ?

Private Sub CmdBack_Click()
If IsNull(Me.TypeID) Then
MsgBox "please enter company !!! "
DoCmd.CancelEvent
Else
DoCmd.OpenForm "FOrderInformation"
End If

Private Sub AddIt_Click()
DoCmd.GoToRecord , "", acNewRec
End Sub
Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 26 Feb 2004 22:36:51 -0800, ke**@abv.bg (Johm) wrote:

I'm not quite following your code, but I would start with making
CustomerName required in the Customers table.

Your code in the Unload event doesn't use the Cancel argument?

And it tests the TypeID field to find out if CustomerName is filled
out?

-Tom.

In my form customers i want to forbid the user to leave the record if
he has not written the CompanyName.To do this, i have put in the unolad
event the following

Private Sub Form_Unload(Cancel As Integer)
If IsNull(Me.TypeID) Then
MsgBox "please enter company !!! "
DoCmd.CancelEvent
End If
End Sub

I also have a button called back with which i return to the main form.
I also have another button called AddIt, with which the new client is entered.
My problem is, that when we open the form with the button AddIt,we can
leave the from with the button Back even no company name is being entered.
In this way i allow the user to leave the form with a blank company name
and in fact my code in the OnOnload event is useless.
May i ask for help ?

Private Sub CmdBack_Click()
If IsNull(Me.TypeID) Then
MsgBox "please enter company !!! "
DoCmd.CancelEvent
Else
DoCmd.OpenForm "FOrderInformation"
End If

Private Sub AddIt_Click()
DoCmd.GoToRecord , "", acNewRec
End Sub


Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.