Help me obie one canoby...you're my only hope!!

Timoty

Registered User.
Local time
Today, 10:02
Joined
Jul 29, 2003
Messages
105
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 think that you want to make the "value" [not the default value] of the combo box the value of the users network name. Maybe using the forms OnOpen event to fill the combo box.

Me.combo21.Value = fOSUserName

Also, you should use some type of standard naming convention for your objects.

cbUserName instead of combo21

HTH
 
Thanks for the reply and the naming advice...I'll take it.
I had already tried the onopen value cammand (and I tried it again just to make sure). Like the default value, it throws the user name into the combo box. However, it still doesn't actually select the user name. It is still sitting on the first record. I actually have to drop down the box and select it. I would thing that it should select the corresponding user id just as if I was typing in the userid but it doesn't. Any other ideas?
 
Try to requery the form. If that doesn't work, try to requery all the fields that are not filing in properly. I would place the requery behind the on open event of the form.
 
Thanks for the replies. I have found a workaround for the problem. This forum has been an invaluable tool.

:D
 
I agree 110%. I have used this forum more then my fair share.
 

Users who are viewing this thread

Back
Top Bottom