Avatar of Murray Brown
Murray Brown
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Access VBA Code or event to see if user has started to enter a new record

Hi

On an Access form what VBA code would I use to check whether the user has begun adding a new record?

Thanks
Microsoft AccessVBA

Avatar of undefined
Last Comment
PatHartman

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Anders Ebro (Microsoft MVP)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Dale Fye

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
PatHartman

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Murray Brown

ASKER
Hi. So far I have the following code but it fires as I enter the first field value. I want it to fire as I try to go to the next record


Private Sub Form_BeforeUpdate(Cancel As Integer)

  If Me.NewRecord = True Then
    'NewRecord so do This
    If validate = False Then
        MsgBox "Please fill out all mandatory fields in new ammunition entry!"
    End If
  Else
    'Existing record being updated, do something else
    If validate = False Then
        MsgBox "Please fill out all mandatory fields in existing ammunition entry!"
    End If
  End If
  
End Sub

Function validate()

    If Len(Nz(Me.Headstamp, "")) < 1 Then
       MsgBox "Please fill in headstamp in ammunition list", , "CAVR - ATD (Ammunition)"
       validate = False: Exit Function
    End If
    
    If Me.Calibre.ListIndex = -1 Then
       MsgBox "Please fill in calibre in ammunition list", , "CAVR - ATD (Ammunition)"
       validate = False: Exit Function
    End If
    
       If Nz(Me.Quantity, 0) < 1 Then
        MsgBox "You must enter a quantity of at least one", , "CAVR - ATD"
       validate = False: Exit Function
    End If
    
    validate = True
    
End Function

Open in new window

PatHartman

If the code is firing when you enter data in the first field, there is code in one of that control's events that is forcing the record to be saved.  You need to post all the code for the form and tell us which control is causing the problem.
Murray Brown

ASKER
Thanks for the help
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
PatHartman

So, does that mean that you found the code that was causing the problem?
Murray Brown

ASKER
Yes Pat.  I had a lot of extra code allover the place that I removed
PatHartman

When I know I don't need code, I simply remove it to remove the clutter.  While I'm testing though, I sometimes comment out blocks of code as I try other things.  It is important to clean up after the fact.  Keeping old code around doesn't help and it can cause issues.

Glad you worked it out.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.