How to display a msgbox if on data change if field value wasn't nu

G

Guest

Is this possible to accomplish?

A field (MyField) contains some text. When a user changes or deletes that
text, I display a message box asking the user if he really wanted to change
the text in MyField. The way my code is set up, the message box displays
after every data change. (I'm not very good at writing code.)

Dim ChgAnswer As Integer, MsgTitle As String, MsgDialog As Integer
Const MB_YESNO = 4
Const MB_ICONEXCLAMATION = 48
Const MB_DEFBUTTON1 = 0, IDYES = 6, IDNO = 7

If Not IsNull(Me.MyField) Then
Beep
MsgTitle = "Data Change"
MsgDialog = MB_YESNO + MB_ICONEXCLAMATION + MB_DEFBUTTON1
ChgAnswer = MsgBox("Do you really want to change the data in this
field?", MsgDialog, MsgTitle)

If ChgAnswer = IDNO Then
Me.Undo
End If
End If


I want the message box to appear ONLY if MyField already contained a value.
If the field was null, I don't want the message box to display.

What's the best event to use for this purpose? (I'm currently using
BeforeUpdate.) Can anyone help clean up my code?

Thanks very much.
 
G

Guest

Hi Gina,

You could do this:

At the top of the form's module:

Option Compare Database
Option Explicit
Dim strMyFieldStartValue as String

Then in the forms 'Current' event:

strControlStartValue = Me.MyField

Then, in the before update of MyField

If IsNull(strMyFieldStartValue) Then
rest of your code

Think that would work.
CW
 
L

luanhoxung

Is this possible to accomplish?

A field (MyField) contains some text. When a user changes or deletes that
text, I display a message box asking the user if he really wanted to change
the text in MyField. The way my code is set up, the message box displays
after every data change. (I'm not very good at writing code.)

Dim ChgAnswer As Integer, MsgTitle As String, MsgDialog As Integer
Const MB_YESNO = 4
Const MB_ICONEXCLAMATION = 48
Const MB_DEFBUTTON1 = 0, IDYES = 6, IDNO = 7

If Not IsNull(Me.MyField) Then
Beep
MsgTitle = "Data Change"
MsgDialog = MB_YESNO + MB_ICONEXCLAMATION + MB_DEFBUTTON1
ChgAnswer = MsgBox("Do you really want to change the data in this
field?", MsgDialog, MsgTitle)

If ChgAnswer = IDNO Then
Me.Undo
End If
End If

I want the message box to appear ONLY if MyField already contained a value.
If the field was null, I don't want the message box to display.

What's the best event to use for this purpose? (I'm currently using
BeforeUpdate.) Can anyone help clean up my code?

Thanks very much.

Hi,
Allow me give my thought for this:
On Event Enter of your Control try use:
If Not IsNull(Me.Field) then
If (msgbox("Do you want to change the data in this field?",
vbYesNo, "Data Change") = vbNo then
Me.NextControl.SetFocus
End If
End If
Just air Code, but I used it for my Invoice which the user want to
amend UnitPrice.

HTH
Luan
 

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