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
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