Hi,
I am currently making a database which has a access front end and SQL back end, Here is some background info and the setup I have.
I have one form that enters data into the database but on that form it has a users box (Who put the item in the database), This box pulls the username from the active directory domain using this VBA Module:
Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX <> 0 Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = ""
End If
Then in the form I have a text box which has the default value of: =DLookUp("USER_ID","USER_ID_FROM_SYSTEM_QRY")
This is the SQL code behind the "USER_ID_FROM_SYSTEM_QRY":
SELECT dbo_USER.USER_ID, dbo_USER.USER_NAME, dbo_USER.USER_LOGIN
FROM dbo_USER
WHERE dbo_USER.USER_ID = (SELECT dbo_USER.USER_ID FROM dbo_USER WHERE dbo_USER.USER_LOGIN =fOSUserName() );
Now this works fine I face the issue of, A second user will then edit this item further and I have a second user box for this part which is a separate column in the table, So We know who edited the item in part 2 of the items data in the database.
If I open the form in normal data entry mode this box above works for the second user BUT if I open the same form in edit mode (as the second user is editing the the record the first user has created) then this box does not work and remain blank.
Hopefully the above makes sense and any help will be great.