Hi all
I'm in dire need of some help to come up with a solution for something I've been struggling with for some time now.
I have a data entry form for users on which they can create, edit & delete records. Essentially I don't want to allow the form to append any newly entered data to the table (i.e. save, update) if the name field is empty. Sounds simple. I have tried numerous vba solutions using the BeforeUpdate event, declaring a global variable which cancels the update. But nothing I do seems to get the desired result.
The problem stems from the fact that there are multiple ways that the form would usually force an update e.g. closing it, navigating to another record etc.. and some custom buttons which I have, namely 'Save & Close' and 'New'. All of which when activated attempt to save and therefore conflict with anything I put in the BeforeUpdate event and vice versa. What I think I need to be able to do is, stop the update event from another sub-routine. For example: (The red text is where I need a line of code that stops the form from updating)
I hope I haven't made a complete ballsup of that explanation, and that some extraordinarily clever person can come and tell me how to fix it!! Thansk in advance for taking a look.
I'm in dire need of some help to come up with a solution for something I've been struggling with for some time now.
I have a data entry form for users on which they can create, edit & delete records. Essentially I don't want to allow the form to append any newly entered data to the table (i.e. save, update) if the name field is empty. Sounds simple. I have tried numerous vba solutions using the BeforeUpdate event, declaring a global variable which cancels the update. But nothing I do seems to get the desired result.
The problem stems from the fact that there are multiple ways that the form would usually force an update e.g. closing it, navigating to another record etc.. and some custom buttons which I have, namely 'Save & Close' and 'New'. All of which when activated attempt to save and therefore conflict with anything I put in the BeforeUpdate event and vice versa. What I think I need to be able to do is, stop the update event from another sub-routine. For example: (The red text is where I need a line of code that stops the form from updating)
Code:
Public Sub cmdSave_Click()
If Me.FirstName = "" Or IsNull(Me.FirstName) Or Me.Surname = "" Or IsNull(Me.Surname) Then
If MsgBox("Can't save record, no name given. Continue without saving?", vbYesNo, "Warning") = vbYes Then
[COLOR=Red]Update Cancel = True[/COLOR]
DoCmd.OpenForm "frmMenu", , , , , , Me.OpenArgs
DoCmd.Close acForm, "frmCourses"
Else
Exit Sub
End If
Else
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenForm "frmMenu", , , , , , Me.OpenArgs
DoCmd.Close acForm, "frmCourses"
End If
End Sub