Me.Dirty - not catching changes

D

DJW

I have a form with a tab control and three pages (tabs) under that control.
Each page has a subform on it.

What I'm trying to do is check all the controls located on the subform on
page 2 for any changes (dirty) when I click on another tab (page).

I have code now that catches any changes when I click on controls (previous
record, next record, add record) located within the subform located on page
2. However, when I "dirty the record" and then click on another tab, it
does not catch the changes and apparently saves the changes as when I click
back to page 2 the changes are still present.

Below is the code I have for checking the controls on page 2 (subform name
is 'frmsub_Evidence'). This code runs within the subform. I want to run it
when I leave the subform and click on another tab. Where do I place the
code to do this? Any help appreciated.




If Me.Dirty Then 'Checks if any changes were made.
GoTo Question
Else
GoTo Step3
End If

Question:
Message = "Changes made! Do you wish to save?" 'Gives
option to save changes.
If MsgBox(Message, vbQuestion + vbYesNo, "Save Record?") = vbYes Then
GoTo Step1
Else
DoCmd.RunCommand acCmdUndo 'Undoes any changes.
GoTo Step4
End If

Step1: 'Check to make sure all required fields contain information.
If IsNull(Me![Case Number]) Then
MsgBox "What is the Case Number?"
Me![Case Number].SetFocus
ElseIf IsNull(Me![Submitted As]) Then
MsgBox "The Item was Submitted as what?"
Me![Submitted As].SetFocus
ElseIf IsNull(Me![Date Submitted]) Then
MsgBox "When was the Item Submitted?"
Me![Date Submitted].SetFocus
ElseIf Not IsNull(Me![Removal Date]) Then
GoTo Step2
Else
GoTo Step3

Step2:
If IsNull(Me![Released By]) Then
MsgBox "Enter intials of Tech releasing the property."
Me![Released By].SetFocus
ElseIf IsNull(Me![Requested By]) Then
MsgBox "Which employee is requesting this item?"
Me![Requested By].SetFocus
ElseIf IsNull(Me![Reason For Removal]) Then
MsgBox "Specify the reason the item was removed."
Me![Reason For Removal].SetFocus
ElseIf IsNull(Me![Recieved By]) Then
MsgBox "Who Recieved the Item?"
Me![Recieved By].SetFocus
Me![Record Updated By] = LoginNameField 'Enters variable value of
LoginNameField.
Else
GoTo Step3

Step3:

' DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
'Saves record.
DoCmd.RunCommand acCmdRefresh 'Refreshes record to show change after
save.
Me.Repaint 'Repaints the screen to show updated record.
GoTo Step4

Step4:
'Do Nothing

Exit Sub

End If
End If
 
S

Steve Schapel

DJW,

When you move the focus to another tab page, it is too late at this
point to be testing the Dirty property of the subform. You have already
left trhe subform, and when you do that, any changes are saved
automatically, so by the time you arrive at the next destination the
subform is not dirty any more. Maybe it would be applicable to put your
code on the subform's Exit event?

--
Steve Schapel, Microsoft Access MVP

I have a form with a tab control and three pages (tabs) under that control.
Each page has a subform on it.

What I'm trying to do is check all the controls located on the subform on
page 2 for any changes (dirty) when I click on another tab (page).

I have code now that catches any changes when I click on controls (previous
record, next record, add record) located within the subform located on page
2. However, when I "dirty the record" and then click on another tab, it
does not catch the changes and apparently saves the changes as when I click
back to page 2 the changes are still present.

Below is the code I have for checking the controls on page 2 (subform name
is 'frmsub_Evidence'). This code runs within the subform. I want to run it
when I leave the subform and click on another tab. Where do I place the
code to do this? Any help appreciated.




If Me.Dirty Then 'Checks if any changes were made.
GoTo Question
Else
GoTo Step3
End If

Question:
Message = "Changes made! Do you wish to save?" 'Gives
option to save changes.
If MsgBox(Message, vbQuestion + vbYesNo, "Save Record?") = vbYes Then
GoTo Step1
Else
DoCmd.RunCommand acCmdUndo 'Undoes any changes.
GoTo Step4
End If

Step1: 'Check to make sure all required fields contain information.
If IsNull(Me![Case Number]) Then
MsgBox "What is the Case Number?"
Me![Case Number].SetFocus
ElseIf IsNull(Me![Submitted As]) Then
MsgBox "The Item was Submitted as what?"
Me![Submitted As].SetFocus
ElseIf IsNull(Me![Date Submitted]) Then
MsgBox "When was the Item Submitted?"
Me![Date Submitted].SetFocus
ElseIf Not IsNull(Me![Removal Date]) Then
GoTo Step2
Else
GoTo Step3

Step2:
If IsNull(Me![Released By]) Then
MsgBox "Enter intials of Tech releasing the property."
Me![Released By].SetFocus
ElseIf IsNull(Me![Requested By]) Then
MsgBox "Which employee is requesting this item?"
Me![Requested By].SetFocus
ElseIf IsNull(Me![Reason For Removal]) Then
MsgBox "Specify the reason the item was removed."
Me![Reason For Removal].SetFocus
ElseIf IsNull(Me![Recieved By]) Then
MsgBox "Who Recieved the Item?"
Me![Recieved By].SetFocus
Me![Record Updated By] = LoginNameField 'Enters variable value of
LoginNameField.
Else
GoTo Step3

Step3:

' DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
'Saves record.
DoCmd.RunCommand acCmdRefresh 'Refreshes record to show change after
save.
Me.Repaint 'Repaints the screen to show updated record.
GoTo Step4

Step4:
'Do Nothing

Exit Sub

End If
End If
 
D

DJW

Thank you for your response. I am having problems finding the Exit event.
Is this same as "lostfocus", "deactivate" or "unload". I don't find
anything for "Exit". Any further help appreciated.

Thank you.






Steve Schapel said:
DJW,

When you move the focus to another tab page, it is too late at this point
to be testing the Dirty property of the subform. You have already left
trhe subform, and when you do that, any changes are saved automatically,
so by the time you arrive at the next destination the subform is not dirty
any more. Maybe it would be applicable to put your code on the subform's
Exit event?

--
Steve Schapel, Microsoft Access MVP

I have a form with a tab control and three pages (tabs) under that
control. Each page has a subform on it.

What I'm trying to do is check all the controls located on the subform on
page 2 for any changes (dirty) when I click on another tab (page).

I have code now that catches any changes when I click on controls
(previous record, next record, add record) located within the subform
located on page 2. However, when I "dirty the record" and then click on
another tab, it does not catch the changes and apparently saves the
changes as when I click back to page 2 the changes are still present.

Below is the code I have for checking the controls on page 2 (subform
name is 'frmsub_Evidence'). This code runs within the subform. I want
to run it when I leave the subform and click on another tab. Where do I
place the code to do this? Any help appreciated.




If Me.Dirty Then 'Checks if any changes were made.
GoTo Question
Else
GoTo Step3
End If

Question:
Message = "Changes made! Do you wish to save?" 'Gives
option to save changes.
If MsgBox(Message, vbQuestion + vbYesNo, "Save Record?") = vbYes Then
GoTo Step1
Else
DoCmd.RunCommand acCmdUndo 'Undoes any changes.
GoTo Step4
End If

Step1: 'Check to make sure all required fields contain information.
If IsNull(Me![Case Number]) Then
MsgBox "What is the Case Number?"
Me![Case Number].SetFocus
ElseIf IsNull(Me![Submitted As]) Then
MsgBox "The Item was Submitted as what?"
Me![Submitted As].SetFocus
ElseIf IsNull(Me![Date Submitted]) Then
MsgBox "When was the Item Submitted?"
Me![Date Submitted].SetFocus
ElseIf Not IsNull(Me![Removal Date]) Then
GoTo Step2
Else
GoTo Step3

Step2:
If IsNull(Me![Released By]) Then
MsgBox "Enter intials of Tech releasing the property."
Me![Released By].SetFocus
ElseIf IsNull(Me![Requested By]) Then
MsgBox "Which employee is requesting this item?"
Me![Requested By].SetFocus
ElseIf IsNull(Me![Reason For Removal]) Then
MsgBox "Specify the reason the item was removed."
Me![Reason For Removal].SetFocus
ElseIf IsNull(Me![Recieved By]) Then
MsgBox "Who Recieved the Item?"
Me![Recieved By].SetFocus
Me![Record Updated By] = LoginNameField 'Enters variable value of
LoginNameField.
Else
GoTo Step3

Step3:

' DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70 'Saves record.
DoCmd.RunCommand acCmdRefresh 'Refreshes record to show change after
save.
Me.Repaint 'Repaints the screen to show updated record.
GoTo Step4

Step4:
'Do Nothing

Exit Sub

End If
End If
 
W

Wayne Morgan

The Exit event is actually on the subform control that holds the subform.

--
Wayne Morgan
MS Access MVP


DJW said:
Thank you for your response. I am having problems finding the Exit event.
Is this same as "lostfocus", "deactivate" or "unload". I don't find
anything for "Exit". Any further help appreciated.

Thank you.






Steve Schapel said:
DJW,

When you move the focus to another tab page, it is too late at this point
to be testing the Dirty property of the subform. You have already left
trhe subform, and when you do that, any changes are saved automatically,
so by the time you arrive at the next destination the subform is not
dirty any more. Maybe it would be applicable to put your code on the
subform's Exit event?

--
Steve Schapel, Microsoft Access MVP

I have a form with a tab control and three pages (tabs) under that
control. Each page has a subform on it.

What I'm trying to do is check all the controls located on the subform
on page 2 for any changes (dirty) when I click on another tab (page).

I have code now that catches any changes when I click on controls
(previous record, next record, add record) located within the subform
located on page 2. However, when I "dirty the record" and then click on
another tab, it does not catch the changes and apparently saves the
changes as when I click back to page 2 the changes are still present.

Below is the code I have for checking the controls on page 2 (subform
name is 'frmsub_Evidence'). This code runs within the subform. I want
to run it when I leave the subform and click on another tab. Where do I
place the code to do this? Any help appreciated.




If Me.Dirty Then 'Checks if any changes were made.
GoTo Question
Else
GoTo Step3
End If

Question:
Message = "Changes made! Do you wish to save?" 'Gives
option to save changes.
If MsgBox(Message, vbQuestion + vbYesNo, "Save Record?") = vbYes
Then
GoTo Step1
Else
DoCmd.RunCommand acCmdUndo 'Undoes any changes.
GoTo Step4
End If

Step1: 'Check to make sure all required fields contain information.
If IsNull(Me![Case Number]) Then
MsgBox "What is the Case Number?"
Me![Case Number].SetFocus
ElseIf IsNull(Me![Submitted As]) Then
MsgBox "The Item was Submitted as what?"
Me![Submitted As].SetFocus
ElseIf IsNull(Me![Date Submitted]) Then
MsgBox "When was the Item Submitted?"
Me![Date Submitted].SetFocus
ElseIf Not IsNull(Me![Removal Date]) Then
GoTo Step2
Else
GoTo Step3

Step2:
If IsNull(Me![Released By]) Then
MsgBox "Enter intials of Tech releasing the property."
Me![Released By].SetFocus
ElseIf IsNull(Me![Requested By]) Then
MsgBox "Which employee is requesting this item?"
Me![Requested By].SetFocus
ElseIf IsNull(Me![Reason For Removal]) Then
MsgBox "Specify the reason the item was removed."
Me![Reason For Removal].SetFocus
ElseIf IsNull(Me![Recieved By]) Then
MsgBox "Who Recieved the Item?"
Me![Recieved By].SetFocus
Me![Record Updated By] = LoginNameField 'Enters variable value of
LoginNameField.
Else
GoTo Step3

Step3:

' DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70 'Saves record.
DoCmd.RunCommand acCmdRefresh 'Refreshes record to show change after
save.
Me.Repaint 'Repaints the screen to show updated record.
GoTo Step4

Step4:
'Do Nothing

Exit Sub

End If
End If
 
D

DJW

Thank you for your response but it doesn't solve my original problem. The
only "exit event" I can find on the subform are associated with each control
on the subform. If I use the exit event which is tied to each single
control on the subform, I have to repeat the same code for each control (22
controls total) as I never know which control I might be exiting from. I
tried most of the options available to the subform itself such as
("lostfocus", "deactivate" or "unload" and a host of others) to no avail.

Basically what I am doing is making a change in any of the 22 fields on a
subform located under tab1. I then click directly on tab2 to work on a
different subform. I want to use the code written below to catch and check
any changes before leaving the subform on tab1 and going on to tab2. So
what I'm really looking for is the correct action in that particular
sequence of events to place the code.

The only one that works 'partially' is the "beforeupdate" option on the
subform but the problem with using that option is it goes through the code
only once and does not stop and repeat the code to check again when a change
has been corrected. It then opens up tab2 which I don't want to get to
until the code parameters have been satisfied.

I apologize for not being real clear about this earlier. Thank you though
for trying to help me.



Wayne Morgan said:
The Exit event is actually on the subform control that holds the subform.

--
Wayne Morgan
MS Access MVP


DJW said:
Thank you for your response. I am having problems finding the Exit
event. Is this same as "lostfocus", "deactivate" or "unload". I don't
find anything for "Exit". Any further help appreciated.

Thank you.






Steve Schapel said:
DJW,

When you move the focus to another tab page, it is too late at this
point to be testing the Dirty property of the subform. You have already
left trhe subform, and when you do that, any changes are saved
automatically, so by the time you arrive at the next destination the
subform is not dirty any more. Maybe it would be applicable to put your
code on the subform's Exit event?

--
Steve Schapel, Microsoft Access MVP


DJW wrote:
I have a form with a tab control and three pages (tabs) under that
control. Each page has a subform on it.

What I'm trying to do is check all the controls located on the subform
on page 2 for any changes (dirty) when I click on another tab (page).

I have code now that catches any changes when I click on controls
(previous record, next record, add record) located within the subform
located on page 2. However, when I "dirty the record" and then click
on another tab, it does not catch the changes and apparently saves the
changes as when I click back to page 2 the changes are still present.

Below is the code I have for checking the controls on page 2 (subform
name is 'frmsub_Evidence'). This code runs within the subform. I want
to run it when I leave the subform and click on another tab. Where do
I place the code to do this? Any help appreciated.




If Me.Dirty Then 'Checks if any changes were made.
GoTo Question
Else
GoTo Step3
End If

Question:
Message = "Changes made! Do you wish to save?" 'Gives
option to save changes.
If MsgBox(Message, vbQuestion + vbYesNo, "Save Record?") = vbYes
Then
GoTo Step1
Else
DoCmd.RunCommand acCmdUndo 'Undoes any changes.
GoTo Step4
End If

Step1: 'Check to make sure all required fields contain information.
If IsNull(Me![Case Number]) Then
MsgBox "What is the Case Number?"
Me![Case Number].SetFocus
ElseIf IsNull(Me![Submitted As]) Then
MsgBox "The Item was Submitted as what?"
Me![Submitted As].SetFocus
ElseIf IsNull(Me![Date Submitted]) Then
MsgBox "When was the Item Submitted?"
Me![Date Submitted].SetFocus
ElseIf Not IsNull(Me![Removal Date]) Then
GoTo Step2
Else
GoTo Step3

Step2:
If IsNull(Me![Released By]) Then
MsgBox "Enter intials of Tech releasing the property."
Me![Released By].SetFocus
ElseIf IsNull(Me![Requested By]) Then
MsgBox "Which employee is requesting this item?"
Me![Requested By].SetFocus
ElseIf IsNull(Me![Reason For Removal]) Then
MsgBox "Specify the reason the item was removed."
Me![Reason For Removal].SetFocus
ElseIf IsNull(Me![Recieved By]) Then
MsgBox "Who Recieved the Item?"
Me![Recieved By].SetFocus
Me![Record Updated By] = LoginNameField 'Enters variable value of
LoginNameField.
Else
GoTo Step3

Step3:

' DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70 'Saves record.
DoCmd.RunCommand acCmdRefresh 'Refreshes record to show change
after save.
Me.Repaint 'Repaints the screen to show updated record.
GoTo Step4

Step4:
'Do Nothing

Exit Sub

End If
End If
 
S

Steve Schapel

DJW,

This is what Wayne meant... go to the design view of the main form, and
select the subform control for the subform that you are concerned about.
This subform control has an Exit event. You will note that the Exit
event allows for the event to be cancelled, which you may want to use in
your code, if the conditions relating to the subform's data are not
satisfied.
 
T

tina

The only one that works 'partially' is the "beforeupdate" option on the
subform but the problem with using that option is it goes through the code
only once and does not stop and repeat the code to check again when a change
has been corrected.

the form's BeforeUpdate event is the usual place to validate multiple field
values. if the code you posted is the actual code you used in your subform's
BeforeUpdate event, then the reason it didn't work is because you didn't
Cancel the event when a field failed the validation test.

try the following code on your *subform* BeforeUpdate event. (btw, it's
generally not a good idea to use GoTo statements in VBA code, except for
error handling. better to call "sub" procedures, if you want to break up
your code for clarity.)

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.Dirty Then
If MsgBox("Changes made! Do you wish to save?", _
vbQuestion + vbYesNo, "Save Record?") = vbYes Then
If isStep1 Then
Cancel = True
End If
Else
Me.Undo
End If
End If

End Sub

Private Function isStep1() As Boolean

isStep1 = False

If IsNull(Me![Case Number]) Then
MsgBox "What is the Case Number?"
Me![Case Number].SetFocus
isStep1 = True
ElseIf IsNull(Me![Submitted As]) Then
MsgBox "The Item was Submitted as what?"
Me![Submitted As].SetFocus
isStep1 = True
ElseIf IsNull(Me![Date Submitted]) Then
MsgBox "When was the Item Submitted?"
Me![Date Submitted].SetFocus
isStep1 = True
ElseIf Not IsNull(Me![Removal Date]) Then
isStep1 = isStep2
End If

End Function

Private Function isStep2() As Boolean

isStep2 = False

If IsNull(Me![Released By]) Then
MsgBox "Enter intials of Tech releasing the property."
Me![Released By].SetFocus
isStep2 = True
ElseIf IsNull(Me![Requested By]) Then
MsgBox "Which employee is requesting this item?"
Me![Requested By].SetFocus
isStep2 = True
ElseIf IsNull(Me![Reason For Removal]) Then
MsgBox "Specify the reason the item was removed."
Me![Reason For Removal].SetFocus
isStep2 = True
ElseIf IsNull(Me![Recieved By]) Then
MsgBox "Who Recieved the Item?"
Me![Recieved By].SetFocus
Me![Record Updated By] = LoginNameField
isStep2 = True
End If

End Function

hth
 
T

tina

oops, you don't need to check the Dirty property when using the BeforeUpdate
event; it only fires when data has been added or changed in a record. use
the following BeforeUpdate event procedure instead (the other two procedures
are fine, as previously posted):

Private Sub Form_BeforeUpdate(Cancel As Integer)

If MsgBox("Changes made! Do you wish to save?", _
vbQuestion + vbYesNo, "Save Record?") = vbYes Then
If isStep1 Then
Cancel = True
End If
Else
Me.Undo
End If

End Sub

hth


tina said:
The only one that works 'partially' is the "beforeupdate" option on the
subform but the problem with using that option is it goes through the code
only once and does not stop and repeat the code to check again when a change
has been corrected.

the form's BeforeUpdate event is the usual place to validate multiple field
values. if the code you posted is the actual code you used in your subform's
BeforeUpdate event, then the reason it didn't work is because you didn't
Cancel the event when a field failed the validation test.

try the following code on your *subform* BeforeUpdate event. (btw, it's
generally not a good idea to use GoTo statements in VBA code, except for
error handling. better to call "sub" procedures, if you want to break up
your code for clarity.)

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.Dirty Then
If MsgBox("Changes made! Do you wish to save?", _
vbQuestion + vbYesNo, "Save Record?") = vbYes Then
If isStep1 Then
Cancel = True
End If
Else
Me.Undo
End If
End If

End Sub

Private Function isStep1() As Boolean

isStep1 = False

If IsNull(Me![Case Number]) Then
MsgBox "What is the Case Number?"
Me![Case Number].SetFocus
isStep1 = True
ElseIf IsNull(Me![Submitted As]) Then
MsgBox "The Item was Submitted as what?"
Me![Submitted As].SetFocus
isStep1 = True
ElseIf IsNull(Me![Date Submitted]) Then
MsgBox "When was the Item Submitted?"
Me![Date Submitted].SetFocus
isStep1 = True
ElseIf Not IsNull(Me![Removal Date]) Then
isStep1 = isStep2
End If

End Function

Private Function isStep2() As Boolean

isStep2 = False

If IsNull(Me![Released By]) Then
MsgBox "Enter intials of Tech releasing the property."
Me![Released By].SetFocus
isStep2 = True
ElseIf IsNull(Me![Requested By]) Then
MsgBox "Which employee is requesting this item?"
Me![Requested By].SetFocus
isStep2 = True
ElseIf IsNull(Me![Reason For Removal]) Then
MsgBox "Specify the reason the item was removed."
Me![Reason For Removal].SetFocus
isStep2 = True
ElseIf IsNull(Me![Recieved By]) Then
MsgBox "Who Recieved the Item?"
Me![Recieved By].SetFocus
Me![Record Updated By] = LoginNameField
isStep2 = True
End If

End Function

hth
 
D

DJW

Tina. Thank you for your help and suggestions. This was the fix I was
looking for and has met my needs as stated. Again, I thank you.




tina said:
oops, you don't need to check the Dirty property when using the
BeforeUpdate
event; it only fires when data has been added or changed in a record. use
the following BeforeUpdate event procedure instead (the other two
procedures
are fine, as previously posted):

Private Sub Form_BeforeUpdate(Cancel As Integer)

If MsgBox("Changes made! Do you wish to save?", _
vbQuestion + vbYesNo, "Save Record?") = vbYes Then
If isStep1 Then
Cancel = True
End If
Else
Me.Undo
End If

End Sub

hth


tina said:
The only one that works 'partially' is the "beforeupdate" option on
the
subform but the problem with using that option is it goes through the code
only once and does not stop and repeat the code to check again when a change
has been corrected.

the form's BeforeUpdate event is the usual place to validate multiple field
values. if the code you posted is the actual code you used in your subform's
BeforeUpdate event, then the reason it didn't work is because you didn't
Cancel the event when a field failed the validation test.

try the following code on your *subform* BeforeUpdate event. (btw, it's
generally not a good idea to use GoTo statements in VBA code, except for
error handling. better to call "sub" procedures, if you want to break up
your code for clarity.)

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.Dirty Then
If MsgBox("Changes made! Do you wish to save?", _
vbQuestion + vbYesNo, "Save Record?") = vbYes Then
If isStep1 Then
Cancel = True
End If
Else
Me.Undo
End If
End If

End Sub

Private Function isStep1() As Boolean

isStep1 = False

If IsNull(Me![Case Number]) Then
MsgBox "What is the Case Number?"
Me![Case Number].SetFocus
isStep1 = True
ElseIf IsNull(Me![Submitted As]) Then
MsgBox "The Item was Submitted as what?"
Me![Submitted As].SetFocus
isStep1 = True
ElseIf IsNull(Me![Date Submitted]) Then
MsgBox "When was the Item Submitted?"
Me![Date Submitted].SetFocus
isStep1 = True
ElseIf Not IsNull(Me![Removal Date]) Then
isStep1 = isStep2
End If

End Function

Private Function isStep2() As Boolean

isStep2 = False

If IsNull(Me![Released By]) Then
MsgBox "Enter intials of Tech releasing the property."
Me![Released By].SetFocus
isStep2 = True
ElseIf IsNull(Me![Requested By]) Then
MsgBox "Which employee is requesting this item?"
Me![Requested By].SetFocus
isStep2 = True
ElseIf IsNull(Me![Reason For Removal]) Then
MsgBox "Specify the reason the item was removed."
Me![Reason For Removal].SetFocus
isStep2 = True
ElseIf IsNull(Me![Recieved By]) Then
MsgBox "Who Recieved the Item?"
Me![Recieved By].SetFocus
Me![Record Updated By] = LoginNameField
isStep2 = True
End If

End Function

hth
 
T

tina

you're welcome :)


DJW said:
Tina. Thank you for your help and suggestions. This was the fix I was
looking for and has met my needs as stated. Again, I thank you.




tina said:
oops, you don't need to check the Dirty property when using the
BeforeUpdate
event; it only fires when data has been added or changed in a record. use
the following BeforeUpdate event procedure instead (the other two
procedures
are fine, as previously posted):

Private Sub Form_BeforeUpdate(Cancel As Integer)

If MsgBox("Changes made! Do you wish to save?", _
vbQuestion + vbYesNo, "Save Record?") = vbYes Then
If isStep1 Then
Cancel = True
End If
Else
Me.Undo
End If

End Sub

hth


tina said:
The only one that works 'partially' is the "beforeupdate" option on
the
subform but the problem with using that option is it goes through the code
only once and does not stop and repeat the code to check again when a
change
has been corrected.

the form's BeforeUpdate event is the usual place to validate multiple field
values. if the code you posted is the actual code you used in your subform's
BeforeUpdate event, then the reason it didn't work is because you didn't
Cancel the event when a field failed the validation test.

try the following code on your *subform* BeforeUpdate event. (btw, it's
generally not a good idea to use GoTo statements in VBA code, except for
error handling. better to call "sub" procedures, if you want to break up
your code for clarity.)

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.Dirty Then
If MsgBox("Changes made! Do you wish to save?", _
vbQuestion + vbYesNo, "Save Record?") = vbYes Then
If isStep1 Then
Cancel = True
End If
Else
Me.Undo
End If
End If

End Sub

Private Function isStep1() As Boolean

isStep1 = False

If IsNull(Me![Case Number]) Then
MsgBox "What is the Case Number?"
Me![Case Number].SetFocus
isStep1 = True
ElseIf IsNull(Me![Submitted As]) Then
MsgBox "The Item was Submitted as what?"
Me![Submitted As].SetFocus
isStep1 = True
ElseIf IsNull(Me![Date Submitted]) Then
MsgBox "When was the Item Submitted?"
Me![Date Submitted].SetFocus
isStep1 = True
ElseIf Not IsNull(Me![Removal Date]) Then
isStep1 = isStep2
End If

End Function

Private Function isStep2() As Boolean

isStep2 = False

If IsNull(Me![Released By]) Then
MsgBox "Enter intials of Tech releasing the property."
Me![Released By].SetFocus
isStep2 = True
ElseIf IsNull(Me![Requested By]) Then
MsgBox "Which employee is requesting this item?"
Me![Requested By].SetFocus
isStep2 = True
ElseIf IsNull(Me![Reason For Removal]) Then
MsgBox "Specify the reason the item was removed."
Me![Reason For Removal].SetFocus
isStep2 = True
ElseIf IsNull(Me![Recieved By]) Then
MsgBox "Who Recieved the Item?"
Me![Recieved By].SetFocus
Me![Record Updated By] = LoginNameField
isStep2 = True
End If

End Function

hth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top