Message Box for editing fields

G

Gabe

Hello,

I couldn't find a thread for this topic.

I have a form with about 10 fields on it, I need a message box to appear
only once if a user attempts to udpate any of the 10 fields.

Currently, when a user updates let's say 5 records out of the 10 fields, the
message box appears 5 times, once for every field they update. I don't want a
message box to appear when the user updates every field, only once for the
entire 10 fields. Is there any way to do that?
 
J

Jack Leach

There might be a better way, but...

Create a variable private to the form's module, call it pIsEditing As Boolean

In the OnCurrent event of the form (every time the form changes records),
set this value to false.

In the BeforeUpdate event of each control on the form, check the value of
pIsEditing. If False, display the message box and set pIsEditing to True.
So the next beforeupdate control event reads IsEditing, see it's true, you
know the message has been displayed already on this record.



Option Compare Database
Option Explicit

Private pIsEditing As Boolean

Private Sub Form_Current()
pIsEditing = False
End Sub

Private Sub Control1_BeforeUpdate(Cancel = True)
If Not pIsEditing Then
MsgBox "Editing Record"
pIsEditing = True
End If
End Sub

Private Sub Control2_BeforeUpdate(Cancel = True)
If Not pIsEditing Then
MsgBox "Editing Record"
pIsEditing = True
End If
End Sub

etc.


hth

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
K

Klatuu

To reduce the amount of repetative code, I would suggest a Function that does
the message and rather than coding an event for each control, just put this
in the Before Update event box on the property sheet for each control:

=CheckMessage()

Private Function Control1_BeforeUpdate(Cancel As Integer)

If Not pIsEditing Then
MsgBox "Editing Record"
pIsEditing = True
End If
End Function
 
G

Gabe

That worked great!

Thanks Jack,
~Gabe


Jack Leach said:
There might be a better way, but...

Create a variable private to the form's module, call it pIsEditing As Boolean

In the OnCurrent event of the form (every time the form changes records),
set this value to false.

In the BeforeUpdate event of each control on the form, check the value of
pIsEditing. If False, display the message box and set pIsEditing to True.
So the next beforeupdate control event reads IsEditing, see it's true, you
know the message has been displayed already on this record.



Option Compare Database
Option Explicit

Private pIsEditing As Boolean

Private Sub Form_Current()
pIsEditing = False
End Sub

Private Sub Control1_BeforeUpdate(Cancel = True)
If Not pIsEditing Then
MsgBox "Editing Record"
pIsEditing = True
End If
End Sub

Private Sub Control2_BeforeUpdate(Cancel = True)
If Not pIsEditing Then
MsgBox "Editing Record"
pIsEditing = True
End If
End Sub

etc.


hth

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 

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