Combo box Help

  • Thread starter Thread starter Raj
  • Start date Start date
R

Raj

I created a combo box using the wizard and I selected
the "Find a record on my form base on the value I
selected in my combo box". How would I change to code to
filter or group all records for the choice I selected and
not just one.
Thank you in advance
This is the code.
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ID] = " & Str(Nz(Me![Combo43], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub
 
I created a combo box using the wizard and I selected
the "Find a record on my form base on the value I
selected in my combo box". How would I change to code to
filter or group all records for the choice I selected and
not just one.
Thank you in advance
This is the code.
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ID] = " & Str(Nz(Me![Combo43], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

Something like

Me.Filter = "[ID] = " & Str(Nz(Me![Combo43], 0))
Me.FilterOn = True
 
John,
Please excuse my ignorance but I am trying to learn VBA
and still figuring things out.. I added the code that you
suggested but I am getting a "Run-time error '13: Type
mismatch error" What am I doing wrong?
Thank you,
Raj
-----Original Message-----
I created a combo box using the wizard and I selected
the "Find a record on my form base on the value I
selected in my combo box". How would I change to code to
filter or group all records for the choice I selected and
not just one.
Thank you in advance
This is the code.
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ID] = " & Str(Nz(Me![Combo43], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

Something like

Me.Filter = "[ID] = " & Str(Nz(Me![Combo43], 0))
Me.FilterOn = True


.
 
John,
Please excuse my ignorance but I am trying to learn VBA
and still figuring things out.. I added the code that you
suggested but I am getting a "Run-time error '13: Type
mismatch error" What am I doing wrong?
Thank you,

Please copy and paste the actual code; also, what is the datatype of
the ID field, and of the bound column of the combo box? The code as
written assumes both are numeric.
 
John,
The data type for [ID] is numeric and the [Combo43]is
Alpha.
There is the actual code from the wizard:

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ID] = " & Str(Nz(Me![Combo43], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub
 
John,
The data type for [ID] is numeric and the [Combo43]is
Alpha.

Eh? So you're trying to search a numeric field for a text value?
That's why you're getting a type mismatch error; to search a numeric
field you need a numeric value.
There is the actual code from the wizard:

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ID] = " & Str(Nz(Me![Combo43], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub
 
John,
What I am trying to do is change this code to make it
work for another combo box.. This combo box [projectname]
list all the project that are used and when you select
the project from the combo box I want it to filter all
the project for that name. The box control source is in a
table [projectname] and is an alpha field. I hope this
make since.

Since the field is Text you need the syntactially required quotemarks:
try

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ID] = '" & Str(Nz(Me![projectname], 0)) & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub
 
Back
Top