code to open blank form activates code to show record has changed

R

Repent

I am trying to get this scenerio to work:

I have the code "DoCmd.GoToRecord , , acNewRec" in the onload event
for a form. it is supposed to open the form to a blank page. it does
open to a blank page, but when I start to make entries on the form,
the code to alert a user that the form is being changed activates. the
code to notify the user the form is being changed is in the "on dirty"
event of the form and is "Detail.BackColor = RGB(255, 100, 100)
InfoMessage.Caption = "You have modified this record. " & _
"If you move to another record, your changes will be applied. " & _
"To cancel your changes, hit the Esc key (top left of keyboard)."

the code to nofity a user that the form is being changed is only
supposed to run when a current record is being changed, not when a
blank record is being changed.

What can I do to have my forms open to a blank entry form but not run
the code that thinks I'm changing a record that already exists?

chris
 
D

Dirk Goldgar

Repent said:
I am trying to get this scenerio to work:

I have the code "DoCmd.GoToRecord , , acNewRec" in the onload event
for a form. it is supposed to open the form to a blank page. it does
open to a blank page, but when I start to make entries on the form,
the code to alert a user that the form is being changed activates. the
code to notify the user the form is being changed is in the "on dirty"
event of the form and is "Detail.BackColor = RGB(255, 100, 100)
InfoMessage.Caption = "You have modified this record. " & _
"If you move to another record, your changes will be applied. " & _
"To cancel your changes, hit the Esc key (top left of keyboard)."

the code to nofity a user that the form is being changed is only
supposed to run when a current record is being changed, not when a
blank record is being changed.

What can I do to have my forms open to a blank entry form but not run
the code that thinks I'm changing a record that already exists?


Place the relevant code in an If block that checks whether you're on a new
record or not. For example,

'----- start of code -----
Private Sub Form_Dirty(Cancel As Integer)

If Not Me.NewRecord Then

Me.Detail.BackColor = RGB(255, 100, 100)

Me.InfoMessage.Caption = "You have modified this record. " & _
"If you move to another record, your changes will be applied. "
& _
"To cancel your changes, hit the Esc key (top left of
keyboard)."

End If

End Sub
'----- end of code -----
 

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