Global Variable as Default Value

Beerman58

New member
Local time
Today, 04:17
Joined
Jul 1, 2008
Messages
5
Hello,

Does anyone know of any way to use a global variable as a default value for a table?

I have a Log-In function called at database startup that [via a "booDBLoginSuccess = ExternalDatabase.ExternalModule.ExternalFunction(UserName,Password)" sort of statement] allows remote login for the database front end. After successful login, the UserName is stored to a public variable in the front end of my database. I want to automatically enter that UserName global variable into a "CreatedBy" field in the relevent tables upon record creation.

Now I know what you are thinking... just add a hidden bounded text field to the form used to add records, then code the Form_BeforeInsert() event to set the value of the field. But there are many ways to add records that would circumvent this event (DAO recordset manipulation via VBA, adding records from a query, adding records directly to the table, another admin creating another form that could add the records without the proper code). It seems that a default value in the back end would be fool proof, and fool proof is the goal.

I tried creating a simple function in the back end that would return the global variable (which is a string), but it seems that access will not allow custom functions in the default value field for field properties in table design (function is not available in equation builder and explicitly typing the function yields an error "unrecognized function" at table save). I also had the thought of creating a separate table only to hold the current UserName value, but it seems from reading other threads that this is not an option for default values either.

Any help, or good reason to give up and use the BeforeInsert event, is much appreciated.

P.S. - Access Version: 2000
 
Sorry, event code in forms is the only way to do this. Jet does not support triggers which is what you would need to control this at the table level. Keep in mind that Jet is a separate product from Access and it is quite possible that Access is not even installed on a computer that is running an application that is using Jet. For that reason, Jet is "unaware" of anything in the VBA environment. The VBA environment may simply not exist if the application using the Jet database is not Access. For example, Jet databases can be the back end for a web application where Access is not involved at all.

You need to get control over the database so that the only updating happens via forms.
 

Users who are viewing this thread

Back
Top Bottom