Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why would the Dropdown event on this combo get this error... 2

Status
Not open for further replies.

GoinDeep

Technical User
Jan 9, 2003
100
US
Can somebody help me figure out why the dropdown portion of the following code gives me the error:

"You can't reference a property or method for a control unless the control has the focus."

This code works for me on other combo's, and it actually works for this combo, but it gives me that error above still.

It gives me the error after I hit enter to update the record

Option Compare Database
Option Explicit

Dim CompanyNameStub As String
Const conCompanyNameMin = 3
Function ReloadCustomersSearch(sCompanyName As String)
Dim sNewCompanyName As String

sNewCompanyName = Nz(Left(sCompanyName, conCompanyNameMin), "")

If sNewCompanyName <> CompanyNameStub Then
If Len(sNewCompanyName) < conCompanyNameMin Then
Me.cmbCustomersSearch.RowSource = "SELECT AccountNumber, CompanyName FROM qry_Customers WHERE (False);"
CompanyNameStub = ""
Else
Me.cmbCustomersSearch.RowSource = "SELECT AccountNumber, CompanyName FROM qry_Customers WHERE (CompanyName Like """ & _
sNewCompanyName & "*"") ORDER BY CompanyName;"
CompanyNameStub = sNewCompanyName
cmbCustomersSearch.Dropdown
End If
End If
End Function

Private Sub cmbCustomersSearch_Change()

Dim cbo As ComboBox
Dim sText As String

Set cbo = Me.cmbCustomersSearch
sText = cbo.Text
Select Case sText
Case " "
cbo = Null
Case Else
Call ReloadCustomersSearch(sText)
End Select
Set cbo = Nothing
End Sub

Private Sub Form_Current()
Call ReloadCustomersSearch(Nz(Me.cmbCustomersSearch, ""))
End Sub


 
Many properties on a control can't be changed unless it has the focus (and just as unintuitively, some properties can't be changed unless the contorl doesn't have the focus - don't you just love how closely coupled Access code is to the user interface!).

I'm guessing the error occurs from Form_Current, at which point some other control has focus. If you just add
Code:
cmbCustomersSearch.SetFocus
at the beginning of the procedure, it should solve your problem.

 
How are ya GoinDeep . . .

. . . and this:
Code:
[blue]            CompanyNameStub = sNewCompanyName
            [purple][b]cmbCustomersSearch.SetFocus[/b][/purple]
	        cmbCustomersSearch.Dropdown[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top