I have a search form that has this code behind below... The problem I'm having is that once I select an option from my ComboBox and an error pops up...
Run-time Error 2185
you cant reference a property or method for a control unless the control has the focus.
I thought in my code I had set the focus on the ComboBox, hovering over the debug line it points to this
Highlighting the section it shows the error message over the part Me.txtInpustSearch.text. but I've been unable to enter anything in that TextBox as the error has popped up before the opportunity to do so.
Where am I going wrong?
Run-time Error 2185
you cant reference a property or method for a control unless the control has the focus.
I thought in my code I had set the focus on the ComboBox, hovering over the debug line it points to this
Code:
sQRY = _
"SELECT * " & vbCrLf & _
"FROM jez.HaH_ReferralReason " & vbCrLf & _
"WHERE jez.HaH_ReferralReason." & Me.cboSearchOn.Text & " LIKE '*" & Me.txtInputSearch.Text & "*' "
Code:
Private Sub txtInputSearch_Change()
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sQRY As String
' On Error GoTo Err
Set cnn = New ADODB.Connection
Set rs = New ADODB.Recordset
cnn.Open "Provider=sqloledb;Data Source=CISSQL1;Initial Catalog=CORPINFO;Integrated Security=SSPI;"
If Not IsNull(cboSearchOn) Then
If Not IsNull(Me.txtInputSearch.Text) Then
Me.cboSearchOn.SetFocus
sQRY = _
"SELECT * " & vbCrLf & _
"FROM jez.HaH_ReferralReason " & vbCrLf & _
"WHERE jez.HaH_ReferralReason." & Me.cboSearchOn.Text & " LIKE '*" & Me.txtInputSearch.Text & "*' "
rs.CursorLocation = adUseClient
rs.Open sQRY, cnn, adOpenForwardOnly, adLockReadOnly
Me.lstSearch.RowSource = sQRY
End If
Else
Me.cboSearchOn.SetFocus
Me.cboSearchOn.Dropdown
End If
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
Exit Sub
'Err:
' basError.LogError VBA.Err, VBA.Error$, "Form_frmTest- txtInputSearch_Change()"
End Sub