Combo box select from Open event in 2007/2010

nschroeder

nschroeder
Local time
Today, 16:35
Joined
Jan 8, 2007
Messages
186
I have a form with code in the Open event that selects the current username as the default value in a combo box from a list of usernames. It's an Access 2003 database, and it works fine for 2003 users, but for 2007/2010 users the selection is blank. In debugger, it selects the value correctly, but still is blank when the form appears. Any ideas on why it's broke in the later versions?

Here's the applicable Open event code:
Code:
    lbAssignee.SetFocus
    lbAssignee.Value = CurUserName()
 
Strange prefix but if it's working in other versions and not throwing any errors then it would have to be a textbox or combo box. A label will fail with the SetFocus method.

Show us your CurUserName() function. Are they all using the same version of Windows?
 
Thanks for your replies. I guess I'm an old-timer. From my early days, I've always referred to combo boxes as list boxes (I never use actual list boxes), so I use lb as the prefix, and lbl for labels. Yes, it's a combo box.

I can't use "TEXT" because that's not an item in the lbAssignee data source.

Here's the CurUserName code, but it's working fine.

Code:
Public Function CurUserName() As String
    If IsNull(CurrentUserName) Then
        Call SetUserVariables
    End If
    CurUserName = CurrentUserName
End Function

I'm guessing it's either a timing issue that's different with 2007/2010, or something needs to be refreshed differently, but stepping through with the debugger should have resolved timing problems, so I'm at a loss. It's not a killer issue -- they can still select their own name -- but it's an unnecessary step that I would like resolved, since more and more users will be convertion to 2010.

Thanks again!
 
That leads me to ask you to show us the CurrentUserName function.

Also, you didn't mention if all the users are using the same version of Windows or not?
By the way, why don't you just put the IsNull() validation in CurrentUserName instead?
 
CurrentUsername isn't a function. It's a global string variable, hence the SetUserVariables functions. As said earlier, the function's working fine and producing the correct result, which shows up in lbAssignee.value in the debugger. It's just not selected when the form appears.

We have all combinations. Some are on XP/Office 2003, XP/Office 2010, Windows 2007/Office 2007, and Windows 2007/Office 2010. It only is a problem with Office 2007 and 2010 users.
 
Alright, so the function definitely returns the right value but that value isn't selected after it's set. Loop through each item in the lbAsignee and check the value against the returned value until you find a match. I suspect that there might be differences in characters, for example a trailing or leading space...
 
That might explain it if it was one or two users having the problem, but the problem is machine-based, not user-based. It works for me personally on Access 2003 machines but not on 2010, and is consistant in the same way for other users. I have stepped through the debugger on both machines, and it is loading lbAssignee.value with "nschroeder" in both cases, but not selecting it. Here's some additional code in Form_Open surrounding the 2 lines I showed earlier. Perhaps something needs to change with the TimerInterval?

Code:
    Application.Echo (False)
    
    DoCmd.Maximize
    lbAssignee.SetFocus
    lbAssignee.Value = CurUserName()
    Loading = True
    FromTimer = False
    OrderByOn = True
    FilterOn = True
    TimerInterval = 100 ' Form is opened from Open event of MainMenu.
                        ' This code allows Open event to finish, then brings Me to the top.
    Call OpenEAForm("EAccessDetail")
    Call OpenEAForm("EAccessPrev")
    Call SetSlaveFormPositions
    Call ShowSpecialFields
    Me.Repaint

    Application.Echo (True)
End Sub
 
That might explain it if it was one or two users having the problem, but the problem is machine-based, not user-based.
No. The reason why I asked you to perform this test is to ensure that a match is actually found in the control before it attempts to set it. That way we know that a match is found but the value is not just being set.
 
I finally got it to work with trial & error by adding a me.requery after setting the combobox value. I have no idea why it's needed for 2010 when it wasn't for 2003, and apparently no one else did either. Thanks for your ideas anyway.
 

Users who are viewing this thread

Back
Top Bottom