Combo box losing focus when populated (1 Viewer)

Keith Nichols

Registered User.
Local time
Today, 19:33
Joined
Jan 27, 2006
Messages
431
I have a hidden combo box that is populated by SQL text in VBA when the user selects an option from a frame select. It is then displayed in drop down mode for the user to select a project. The form then synchronizes to the selection and the combo box is hidden again.

At least that is how it is supposed to work. What happens is that the combobox opens and appears to have lost the focus without a selection being made. The combo box shows no records and I have to click elsewhere in the form to reset things. The weird thing is, when I make a new selection it works perfectly. If I click outside the combo box without making a selection, I get the same situation as the first time it is used.

Using another control on the form resets all this so that I get the same error again. From that, I have guessed that there is something wrong with my code but I cannot see what and I am not terribly experienced in this area.

I tried to make a trap on the combo lost focus property but it generated errors in the after update property.

Can any kind soul take a quick look and give me a pointer on where I have gone wrong and how to write an error trap for no selection being made in the combobox? :)


Code:
Private Sub FrameSelectDept_AfterUpdate()
On Error GoTo ErrHandler
Dim SQLText, Dept, WClause
'====================================================================
'Populate project find combo based on option button clicked
'This sub selects all the active projects (those not marked
'as 'Archived')as the row source for the cboFindProject and
'then displays cboFindProject
'====================================================================
    
'Define Select / From text for SQL
    SQLText = "SELECT [Project_ID],[Project_Title]FROM tbl_Prj_Details "
    
'Check which Department was selected
    Select Case Me![FrameSelectDept]
        Case 1
            Dept = "7"   'EDD
        Case 2
            Dept = "23"  'EDH
        Case 3
            Dept = "13"  'EDL
        Case 4
            Dept = "14"  'EDM
        Case 5
            Dept = "19"  'EDR
        Case 6
            Dept = "3"   'EDT
    End Select

'Assemble Where clause for SQL
    WClause = "WHERE Section_ID = " & Dept & "AND Archive = no order by [Project_Title]"

'Show cboFindProject & label
    GroupShow GroupName:="FindProject", Show:=True
    
'Populate combo box rows using SQL
    With Me![cboFindProject]
        .RowSource = SQLText & WClause
        .Requery
        .SetFocus
    End With
    
Me![cboFindProject].Dropdown
    
ExitHere:
    Exit Sub

ErrHandler:
    MsgBox Err.Number & " - " & Err.Description & Chr(13) _
    & Chr(13) & "Error in 'fdlgPrjDetails': Err 010"
    Resume ExitHere
End Sub
 

Users who are viewing this thread

Top Bottom