error handling

Kevin Campbell

New member
Local time
Today, 15:54
Joined
Feb 23, 2005
Messages
5
i'd like to develop some input validation and handling for a form im working on.

I have one form consisting of only table for that form (input into only one table).
They must input data in one field on the form (required). I have created a simple add button that only adds a new record to the form. Well when you click on the add new button, it creates a new record with a new p.k. in the table. However, users can sometimes not click on the add new button or lets say they navigate to the nth record in the set, if they move into the nth+1 record of the set and start entering data, they'll get an error message saying that the record does not have a p.k. associated with it.

i was thinking of developing some sort of module or vba code, my idea:

if the current record < total record count & the pk.value = null
= execute a new record command for the user when

this code would be contained in the next last record button. Thoughts?
Implementation? Thanks in advance!
 
Have you considered having an auto number field in your table?
 
Primary keys

If you check out my post in the general forum, you might see the problems that develop years later from having a user-entered primary key. You shouldn't try to get fancy with VBA to fix this. You should avoid it with cleaner programming.

Whenever I create a table, no matter what's going into that table (data, lookup fields, etc.), the first field is called ___ID. I'm a medical guy, so it's often PatientID, or SurgeryID, or HospitalID, or DoctorID, or whatever. This I make the primary key, and I allow the db to use it as it sees fit. The disadvantage of having a user-entered field as a primary key is that users can screw it up. Primary keys are something that the db needs to keep internal tabs on the data, and not something users should ever know about.

That doesn't mean that your tables won't have other unique 'Indexed' fields - sure they will. But they don't need to have that cute little 'key' icon next to them in the design view. That will only cause problems in the future.

Best of luck,

Nelson
 

Users who are viewing this thread

Back
Top Bottom