Base has “User Administration” functionality under “Tools” in the menu, which is active only when the database is “split,” meaning it is not an internal HSQLDB. The functionality allows different users to log in through the same LO database front-end. You can query the back-end for the current user by a variety of methods. HSQLDB provides USER() and CURRENT_USER functions, the latter being standard across platforms, but again LO supplies this functionality only when split (apparently-- that is the only situation when it works for me).
There is not a way to set a form’s default value to a function. Thus, you would use a macro to set the value of a blank control using the back-end’s CURRENT_USER as follows:
REM ***** BASIC *****
Sub UpUsr
priForm = ThisComponent.DrawPage.Forms.getByName("MainForm")
txbx1 = priForm.getByName("txbx1")
Conn = priForm.ActiveConnection
SQL = Conn.CreateStatement()
SQLStr = "SELECT `TeacherID` FROM `Teacher` WHERE `UserID`=CURRENT_USER"
results = SQL.executeQuery(SQLStr)
results.first
usr = results.getString(1)
If txbx1.String = "" Then
txbx1.setString(usr)
txbx1.Commit
End If
End Sub
The portion in quotes is the query that returns the TeacherID name from the database where the UserID matches the CURRENT_USER value for the database, in my case, doug@localhost. The Teachers table will have one UserID for each database credential, and a TeacherID associated with that credential.
Activate the macro from an appropriate Form event, such as Before Record Action and it will update the text box named txbx1 located on the form named MainForm (see Form Navigator).
(if this answers your question, please accept the answer by clicking the check (
) to the left)