Macro If NEW record then ...

Is this thread helpful fo you?

  • Yes.

    Votes: 3 100.0%
  • No.

    Votes: 0 0.0%

  • Total voters
    3

Cosmos75

Registered User.
Local time
Today, 11:18
Joined
Apr 22, 2002
Messages
1,281
I have a macro in the beforeupdate that always asked the user if they want to change the current record, if the click OK, the changes are accepted, if the click NO, then the macro runs a CancelEvent, and the user then has to clear his or her changes by clicked ESC. This is great to make sure a user doesn't accidentally change an entered record.

HOWEVER, this macro also runs when a NEW record is trying to be added. Is there a condition I can add in the macro to not run when a new recored is being added?

I've converted the macro to Visual Basic in case that helps.

Function ConfrimEdit()
On Error GoTo ConfirmEdit_Err

If (MsgBox("Accept changesl? If NO, then click Cancel and then ESC. Pressing EQC clears the changes made and allows you to move to another record.", 1, "Are you sure?") = 2) Then
DoCmd.CancelEvent
' Perform the action on this line if the condition on the preceding line is true
SendKeys "{ESC}", False
End If


CEdit2_Exit:
Exit Function

CEdit2_Err:
MsgBox Error$
Resume CEdit2_Exit

End Function
 
Here's what i would do. It may be inefficient, but i think it would work.

Set up a new Yes/No field in the table, [Old]. Set the value for each record to true on AfterUpdate. This gives all old records a True field that you can easily use an if statement with.

so for your BeforeUpdate, ask If([Old] = True) Then

This should solve your problem.
 
Use the NewRecord property.

If Me.NewRecord Then
...
Else
...
End If
 
Pat,

How do I add that to a Macro? I am using a generic macro and refering to it on certain forms.

If it can't be added to a macro, I've taken my macro and converted it to Visual Basic (using Access 2000's convertor) and added the if statement and it works. (It's now a module in my database, whatever that is...:confused: )

But I don't know how to refer to it? :( I've resorted to just copying the code to each forms BeforeUpate code. Is there a better way???

THANKS!:)
 
You can call the sub from the BeforeUpdate event rather than copying the code.

Simply:

YourSub

Or, I prefer the more explicit syntax:

Call YourSub
 

Users who are viewing this thread

Back
Top Bottom