bound column in combo box

G

Guest

My form contains a combo box that allows me to pick a particular client. In
this combo box there are five columns - the first being the bound column.
Once I select the correct record I click on a command button which should
pull up a different form filtered to this combo box selection. However, I
get an error that states "... can't find the field "|" referred to in your
expression".

Private Sub Command116_Click()
DoCmd.OpenForm "frmMain", acNormal, , Me.Cbo108.Column(0) = [ID_No]
End Sub

Any thoughts on what is wrong here?
 
G

Guest

It appears you have your Where argument backwards. It should be
[FieldX] = [SomeValue]

Where
FieldX is a field in the record source of the form you are opening
= is any valid operator
[SomeValue] is the value you want to match in FieldX

DoCmd.OpenForm "frmMain", acNormal, , "[ID_No] = " & Me.Cbo108

Other thoughts:
Me.Cbo108.Column(0) is the same as Me.Cbo108. You only need to reference
the Column when it is not the bound column. I know the Bound Column is 1,
but column numbering starts at 0 which is the first column.

As coded, ID_No should be a numeric field. If it is not numeric, it needs
to use the correct delimiters:
For Text:
DoCmd.OpenForm "frmMain", acNormal, , "[ID_No] = '" & Me.Cbo108 & "'"
For Dates:
DoCmd.OpenForm "frmMain", acNormal, , "[ID_No] = #" & Me.Cbo108 & "#"
 
F

fredg

My form contains a combo box that allows me to pick a particular client. In
this combo box there are five columns - the first being the bound column.
Once I select the correct record I click on a command button which should
pull up a different form filtered to this combo box selection. However, I
get an error that states "... can't find the field "|" referred to in your
expression".

Private Sub Command116_Click()
DoCmd.OpenForm "frmMain", acNormal, , Me.Cbo108.Column(0) = [ID_No]
End Sub

Any thoughts on what is wrong here?

The where clause must be a string with the combo value concatenated
into the string.
Also, you write that the combo first column is the bound column. If
so, then you don't need to reference Column(0).

If the [ID_No] field is a Number datatype:

DoCmd.OpenForm "frmMain", acNormal, , "[ID_No] = " & Me.Cbo108

If the [ID_No] field is Text datatype:

DoCmd.OpenForm "frmMain", acNormal, , "[ID_No] = '" & Me.Cbo108 & "'"

You must make sure the bound column of the combo box is the same
datatype as [ID_No].
 
G

Guest

Dave / Fred,
Your suggestions worked perfectly (as always). Thanks for your help.

fredg said:
My form contains a combo box that allows me to pick a particular client. In
this combo box there are five columns - the first being the bound column.
Once I select the correct record I click on a command button which should
pull up a different form filtered to this combo box selection. However, I
get an error that states "... can't find the field "|" referred to in your
expression".

Private Sub Command116_Click()
DoCmd.OpenForm "frmMain", acNormal, , Me.Cbo108.Column(0) = [ID_No]
End Sub

Any thoughts on what is wrong here?

The where clause must be a string with the combo value concatenated
into the string.
Also, you write that the combo first column is the bound column. If
so, then you don't need to reference Column(0).

If the [ID_No] field is a Number datatype:

DoCmd.OpenForm "frmMain", acNormal, , "[ID_No] = " & Me.Cbo108

If the [ID_No] field is Text datatype:

DoCmd.OpenForm "frmMain", acNormal, , "[ID_No] = '" & Me.Cbo108 & "'"

You must make sure the bound column of the combo box is the same
datatype as [ID_No].
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top