Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Stop People Breaking Into Your Code.
Andrew Clark 
     
2 days ago
This site has given me invaluable tips and thanks to Richard for that. It's time I paid forward.
From past experience I've found the odd nerds who think it's clever to try and break into your coding and induce error messages.
I keep typed inputting a minimum but there are occasions where it can't be avoided.
One of the areas I found where they might try is a date field where there is the accompanying date picker. Not wishing to teach Granny to suck eggs but here's what I found.
I went round the houses with various combinations of KeyPress, KeyDown and MouseDown to stop random alpha numerics or cut and paste being inserted.
The solution was the simplest. My field is 'EnterDate'

Private Sub EnterDate_KeyDown(KeyCode As Integer, Shift As Integer)
    KeyCode = 0
End Sub

Hope someone finds that useful. LLAP
Richard Rost  @Reply  
          
2 days ago
Thanks for paying it forward, Andrew. That's a handy little trick when you want to force users to pick the date with the calendar control instead of typing something unexpected into the box.

Just remember that KeyDown only blocks keyboard input. A user could still potentially change the value through VBA, a paste operation depending on the control behavior, or by editing the underlying table directly. For normal users on a form, though, it is a perfectly reasonable way to make EnterDate calendar-only.

For anything where the date really matters, I would still validate it in the form's BeforeUpdate event. The user interface should guide people toward correct data, but validation is the last line of defense. LLAP.
Andrew Clark OP  @Reply  
     
2 days ago
I get your point. I keep users well away from anything to do with the backend, tables or coding.
My scenario is that the date picker(s) are incorporated into  validation forms where the user ensures that every field, all entered via lists, dropdowns etc. are correct before saving the data to tables. The date picker is there if it's a late entry and the user needs to keep the lists correct.
When the final product is ready I have a whole load of shut off to enable.
'    FS02 "AllowSpecialKeys", dbBoolean, False
'    FS02 "AllowBypassKey", dbBoolean, False
'    FS02 "AllowBreakIntoCode", dbBoolean, False
'    FS02 "StartupShowDBWindow", dbBoolean, False
'    FS02 "AllowFullMenus", dbBoolean, False
'    FS02 "StartupShowStatusBar", dbBoolean, False
'    FS02 "AllowToolbarChanges", dbBoolean, False
If you can think of anythig else please let me know before June next year.
Kevin Yip  @Reply  
     
2 days ago
Are we talking about code injection?  One way to combat that is with parameter queries, in which user inputs are always treated as parameters instead of possible code fragments.
Andrew Clark OP  @Reply  
     
2 days ago
Without going into specifics everything is basically prefabricated. The user selects from a number of preset options and calculations are then rendered. In places where the user is allowed to enter criteria the text is validated by length, Ascii etc. If it meets the validation rules it's a press of a button and the underlying table and queries are updated. Of course they can enter gibberish text but that's their problem.
I would say that it's not the sort of database that is normally discussed here.
Andrew Clark OP  @Reply  
     
2 days ago
Kevin  I have replied to you in the thread.
A Toykan  @Reply  
      
2 days ago
In cases like this, when entering a date and ensuring its accuracy is important, I prefer to open my own date picker form as soon as the control receives focus. If no date is selected, I display a warning asking the user to either select a date or the record will be canceled. After that, it’s up to them.

However, rather than trying to anticipate and deal with people who deliberately try to break your code, I think a better approach is to validate the entered data at the form level, using the BeforeUpdate event.
Add a Reply Upload an Image
Next Unseen

 
 
What's This?

 

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: 9/18/2026 5:52:11 AM. PLT: 0s