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
"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