Control save when form closes

Chunk

Registered User.
Local time
Today, 19:30
Joined
Oct 25, 2004
Messages
64
How can i control what happens when a form is closed.

Say for example if no order lines have been entered on a sub form, the record is not saved.

Also how do you remove the default access error messages about null fields, and replace it with something more user friendly.
 
In the VBA code of your form, add this:
Code:
Private Sub Form_Unload(Cancel As Integer)
{Enter the code you want here}
End Sub

To modify an error message, add this to your code:
Code:
Private Sub YourTextBox_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_YourTextBox_BeforeUpdate
{Enter the code you want here}

Exit_YourTextBox_BeforeUpdate:
    Exit Sub

Err_YourTextBox_BeforeUpdate:
    MsgBox Err.Number
    Resume Exit_YourTextBox_BeforeUpdate
End Sub
Then make the error. The message willnow be a number instead. Then change the previous code for the following:
Code:
Private Sub YourTextBox_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_YourTextBox_BeforeUpdate
{Enter the code you want here}

Exit_YourTextBox_BeforeUpdate:
    Exit Sub

Err_YourTextBox_BeforeUpdate:
    If Err.Number = {Enter the number you received here} then
        msgbox = "{Enter the message you want to appear here}"
    Else
        MsgBox Err.Description
    End if
    Resume Exit_YourTextBox_BeforeUpdate
End Sub
 

Users who are viewing this thread

Back
Top Bottom