BeforeUpdate Issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KatcDolly
    New Member
    • Sep 2016
    • 15

    BeforeUpdate Issue

    I am using MS Access 2010 and trying to do everything in Macros.

    I have a form (frmPt) that must have data in several fields. On the BeforeUpdate event I run this macro:

    Code:
    If Null([txtMRN]) And [Dirty] then
    	MessageBox
    	GoToControl 	txtMRN
    Elseif isNull(cboProviderName) and [Dirty] then
    	Messagebox
    	GoToControl cboProviderName
    ElseIf isnull(opgEvalType) and [Dirty]  then
    	MessageBox
    	GotoControl opgEvalType
    ElseIf isnull(opgHowLate) and [Dirty] then
    	MessageBox
    	GoToControl opgHowLate
    Elseif isnull(opgReason) and [Dirty] then
    	MessageBox
    	GotoControl opgReason
    Elseif cbkReschedule = True
    	If isnull(opgRWhen) then
    		Msgbox
    		GoToControl opgRWhen
    	Elseif isnull(opgRPro) then
    		Msgbox
    		Gotocontrol opgRPro
    	End if
    
    End if
    If I am entering records it works great.

    However, there is a "close" button on the form. If the button is pushed it does not run any of the beforeupdate.

    I tried placing all of this code on the OnClick event of the button adding quit method (see below).

    Code:
    If Null([txtMRN]) And [Dirty] then
    	MessageBox
    	GoToControl 	txtMRN
    Elseif isNull(cboProviderName) and [Dirty] then
    	Messagebox
    	GoToControl cboProviderName
    ElseIf isnull(opgEvalType) and [Dirty]  then
    	MessageBox
    	GotoControl opgEvalType
    ElseIf isnull(opgHowLate) and [Dirty] then
    	MessageBox
    	GoToControl opgHowLate
    Elseif isnull(opgReason) and [Dirty] then
    	MessageBox
    	GotoControl opgReason
    Elseif cbkReschedule = True
    	If isnull(opgRWhen) then
    		Msgbox
    		GoToControl opgRWhen
    	Elseif isnull(opgRPro) then
    		Msgbox
    		Gotocontrol opgRPro
    	End if
    Else
    	Docmd Quit
    End if
    It would run the checking of the data but will not Quit Access.

    Any advice or wisdom would be greatly appreciated.

    Thank you!
  • KatcDolly
    New Member
    • Sep 2016
    • 15

    #2
    I have figured this out. When using Macros Access does not like the nested If...then statement. Combine the Nested If into two ElseIf like so:

    Code:
    If Null([txtMRN]) And [Dirty] then
    	MessageBox
    	GoToControl 	txtMRN
    Elseif isNull(cboProviderName) and [Dirty] then
    	Messagebox
    	GoToControl cboProviderName
    ElseIf isnull(opgEvalType) and [Dirty]  then
    	MessageBox
    	GotoControl opgEvalType
    ElseIf isnull(opgHowLate) and [Dirty] then
    	MessageBox
    	GoToControl opgHowLate
    Elseif isnull(opgReason) and [Dirty] then
    	MessageBox
    	GotoControl opgReason
    Elseif cbkReschedule = True and isnull(opgRWhen) then
    		Msgbox
    		GoToControl opgRWhen
    Elseif cbkReschedule = True and isnull(opgRPro) then
    		Msgbox
    		Gotocontrol opgRPro
    Else
    	Docmd Quit
    End if
    Not sure why, but it works.

    Comment

    Working...