pre-selecting listbox item

billwagnon

New member
Local time
Today, 23:51
Joined
Jan 30, 2003
Messages
9
On a form I have these items:

1. Customer selector.
2. Customer's project selector.
3. Textbox for project name.
4. Subform for project details.

When I select the customer I want to automatically select the last project. The code I am using work except for the automatic selection. If I take out the marked line below and change the customer, the details don't update until I click in the Project listbox to pick the project.

The marked line works to select the project, but the focus appears to be kept on the Customer and moving off Customer results in errors about AddUpdate and Edit.

Code:
[SIZE=1]
Private Sub cboCustomer_Click()
        
    Me!lsbProject.RowSource = "SELECT Project, Project & ' ' &  ProjectName " & _
                                " FROM _Project WHERE Customer='" & cboCustomer.Value & _
                                "' ORDER BY Project"
    Me!lsbProject.Requery
        
   ***** If lsbProject.ListCount > 0 Then _ 
lsbProject.Selected(lsbProject.ListCount - 1) = True *****
    
End Sub

Private Sub lsbProject_Click()

    Me.RecordSource = "SELECT * FROM _Project WHERE Project=" & lsbProject.Value
    Me.Requery
    
End Sub
[/size]

Thanks for any tips!
 
Last edited:

Users who are viewing this thread

Back
Top Bottom