I have surfed this forum for answers successfully but have now finally succumbed to my ignorance and must plead for help.
I have a database that upon opening goes into a login box. On this login box is a combo box that looks up users in a querie based on a table with user names and passwords.
I used code from this forum that pulls the user id from Windows and I can insert this user id into the combo box by using the default value.
However, even though it is inserting the userid, it does not select the user ID. I know this is probably simple but I can’t get out of this box I’m in. I have tried using various code in the onload and onopen to no avail.
The form name is login
The combo box is combo21
The default value for the combo21 is =fOSUserName() which is based on a module with the following code.
Option Compare Database
Option Explicit
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
'----------------------------------------------------------------------------------------------------------------
' This code is used to retrieve the network user name by accessing the API apiGetUserName.
' Created by: Unknown (Found on Dev Ashish web site http://home.att.net/~dashish/api)
' This code has not been altered in anyway.
' Added to database: 19 Feb 2002
' Added by: Richard Rensel
'---------------------------------------------------------------------------------------------------------------
Function fOSUserName() As String
On Error GoTo fOSUserName_Err
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
fOSUserName_Exit:
Exit Function
fOSUserName_Err:
MsgBox Error$
Resume fOSUserName_Exit
End Function
Even though the correct user id is automatically inserted, I still have to manually select the user id from the drop down to select the corresponding recordset. This defeats the purpose of having the userid automatically selected.
Thanks
I have a database that upon opening goes into a login box. On this login box is a combo box that looks up users in a querie based on a table with user names and passwords.
I used code from this forum that pulls the user id from Windows and I can insert this user id into the combo box by using the default value.
However, even though it is inserting the userid, it does not select the user ID. I know this is probably simple but I can’t get out of this box I’m in. I have tried using various code in the onload and onopen to no avail.
The form name is login
The combo box is combo21
The default value for the combo21 is =fOSUserName() which is based on a module with the following code.
Option Compare Database
Option Explicit
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
'----------------------------------------------------------------------------------------------------------------
' This code is used to retrieve the network user name by accessing the API apiGetUserName.
' Created by: Unknown (Found on Dev Ashish web site http://home.att.net/~dashish/api)
' This code has not been altered in anyway.
' Added to database: 19 Feb 2002
' Added by: Richard Rensel
'---------------------------------------------------------------------------------------------------------------
Function fOSUserName() As String
On Error GoTo fOSUserName_Err
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
fOSUserName_Exit:
Exit Function
fOSUserName_Err:
MsgBox Error$
Resume fOSUserName_Exit
End Function
Even though the correct user id is automatically inserted, I still have to manually select the user id from the drop down to select the corresponding recordset. This defeats the purpose of having the userid automatically selected.
Thanks