I
Ian Chappel
I am trying to alter the Rowsource of a ComboBox to display only records
that match any text I have typed into the Combo. I have AutoExpand set to
No.
All works fine apart from two niggles:
1. I can't seem to detect when I only have narrowed down to only one
record - I am getting an error message "Object variable or With block
variable not set" if I include the "If .Recordset.RecordCount > 1 Then"
line.
2. I would like to avoid having the contents of other instances of this
ComboBox (it is on a Continuous Form) loose their displayed contents when I
filter the Rowsource. I have a feeling thought that this might not be
possible!
Here's my code:
_____________________________________________________________________
Private Sub cboNominal_Change()
Dim strEntered As String
Const strMainSQL = "SELECT tblNominals.NomID, tblNominals.NomName FROM
tblNominals"
Dim strWhereSQL As String
With Me!cboNominal
strEntered = .Text
.RowSourceType = "Table/Query"
If Len(strEntered) < 3 Then
strWhereSQL = ""
.RowSource = strMainSQL
Else
strWhereSQL = " WHERE tblNominals.NomName Like '*" & strEntered
& "*'"
.RowSource = strMainSQL & strWhereSQL
'If .Recordset.RecordCount > 1 Then ' **********This line seems
to be the problem **********
.Dropdown
'End If
End If
End With
End Sub
_____________________________________________________________________
Thanks.
that match any text I have typed into the Combo. I have AutoExpand set to
No.
All works fine apart from two niggles:
1. I can't seem to detect when I only have narrowed down to only one
record - I am getting an error message "Object variable or With block
variable not set" if I include the "If .Recordset.RecordCount > 1 Then"
line.
2. I would like to avoid having the contents of other instances of this
ComboBox (it is on a Continuous Form) loose their displayed contents when I
filter the Rowsource. I have a feeling thought that this might not be
possible!
Here's my code:
_____________________________________________________________________
Private Sub cboNominal_Change()
Dim strEntered As String
Const strMainSQL = "SELECT tblNominals.NomID, tblNominals.NomName FROM
tblNominals"
Dim strWhereSQL As String
With Me!cboNominal
strEntered = .Text
.RowSourceType = "Table/Query"
If Len(strEntered) < 3 Then
strWhereSQL = ""
.RowSource = strMainSQL
Else
strWhereSQL = " WHERE tblNominals.NomName Like '*" & strEntered
& "*'"
.RowSource = strMainSQL & strWhereSQL
'If .Recordset.RecordCount > 1 Then ' **********This line seems
to be the problem **********
.Dropdown
'End If
End If
End With
End Sub
_____________________________________________________________________
Thanks.