limit records in a table by using VBA code

johnqzsmith

Registered User.
Local time
Today, 10:32
Joined
Apr 25, 2004
Messages
13
I would like to find a way to limit records in a table by using VBA code. I have a couple of tables that contain data specific to the user (licensed). It is my understanding that these are much safer if entered in code vs. sitting out in a table where clever users may track them down.

For example, let’s say I only wanted to allow 3 records into tblMasterTable. I can set the validation rule (in design view of the table) to have the PrimaryKey (integer): > 0 And <= 4. However, I would like to employ a global constant in VBA that would be hidden from the users which would accomplish this same thing, but in a more secure fashion.

E.g., Public Const gconMtableLimit As Integer = 3

That seems easy enough to write out, but how do I “make it stick”. That is, how do I relate that constant to what can/can’t be done with regards to the number of records in tblMasterTbl?

At present, the application is one file, but I will be splitting it soon into fe/be dbs.

Thanks,

JQ
 
Check in some place to see if the number of records is >= MasterVariable. If true, set the allowAdditions property of the form to False. There you go, no new records.

If you're using a single record view Form, then check in Form_Current. Otherwise, check in Form_AfterUpdate.
 

Users who are viewing this thread

Back
Top Bottom