Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
save prompt new record help
Sean Sweeney 
     
4 years ago
Is there a way to bypass this code for new records? I was hoping to use this to protect entries in a continuous form from being accidentally changed

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim ctl As Control

On Error GoTo Err_BeforeUpdate

If Me.Dirty Then
   If MsgBox("Do you want to save?", vbYesNo + vbQuestion, _
           "Save Record") = vbNo Then
      Me.Undo
   End If
End If

Exit_BeforeUpdate:
Exit Sub

Err_BeforeUpdate:
MsgBox Err.Number & " " & Err.Description
Resume Exit_BeforeUpdate
End Sub
Adam Schwanz  @Reply  
           
4 years ago
You could check with DMAX vs the ID.

If ID >= DMAX("ID","Table") Then
'it's a new record
Else
'stuff
End If
Adam Schwanz  @Reply  
           
4 years ago
Sean Sweeney OP  @Reply  
     
4 years ago
Genius! Just Plugged that in before the function, then ended/exited the routine for Dmax Value.

Private Sub LastName_BeforeUpdate(Cancel As Integer)
Dim ctl As Control

On Error GoTo Err_BeforeUpdate
  If TechID >= DMax("PersonID", "TableT") Then
Exit Sub
Else
If Me.Dirty Then
   If MsgBox("Do you want to save?", vbYesNo + vbQuestion, _
           "Save Record") = vbNo Then
      Me.Undo
   End If
End If
End If
Exit_BeforeUpdate:
Exit Sub
Err_BeforeUpdate:
MsgBox Err.Number & " " & Err.Description
Resume Exit_BeforeUpdate
End Sub

Thanks a bunch, Adam!
Sean Sweeney OP  @Reply  
     
4 years ago
.. Meant to take out the "TechID" and replace it with "PersonID" but I was all excited that it worked that I forgot. I actually never worked with Dmax before - so that's such an easy/brilliant solution.
Adam Schwanz  @Reply  
           
4 years ago
Glad it worked :).

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/7/2026 8:21:42 AM. PLT: 0s