Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag 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
ASKER CERTIFIED SOLUTION
Avatar of Anders Ebro (Microsoft MVP)
Anders Ebro (Microsoft MVP)
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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

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.
Thanks for the help
So, does that mean that you found the code that was causing the problem?
Yes Pat.  I had a lot of extra code allover the place that I removed
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.