ORDER BY - comboBox

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

Hi

I've got two comboboxes - one filtering the other. I would like the
filtered combo boxs' contents to be in Alphabetaical order.

Private Sub cboCreditor_AfterUpdate()
Dim strbranch As String

strbranch = "SELECT
[tblcreditoraddresses].[creditoraddressid],[tblcreditoraddresses].[creditorn
ameid], [tblcreditoraddresses].[creditorbranch]" & _
"FROM [tblcreditoraddresses] " & _
"WHERE [creditorNameid] = " & Me.cbocreditor.Value
Me.cbocredbranch.RowSource = strbranch
Me.cbocredbranch.Requery

I'm trying to add; ORDER By [creditorbranch], after the where clause but it
keeps giving me error messages;

compile error: Line number or label or statement or end of statement

Help
 
Hi

I've got two comboboxes - one filtering the other. I would like the
filtered combo boxs' contents to be in Alphabetaical order.

Private Sub cboCreditor_AfterUpdate()
Dim strbranch As String

strbranch = "SELECT
[tblcreditoraddresses].[creditoraddressid],[tblcreditoraddresses].[creditorn
ameid], [tblcreditoraddresses].[creditorbranch]" & _
"FROM [tblcreditoraddresses] " & _
"WHERE [creditorNameid] = " & Me.cbocreditor.Value
Me.cbocredbranch.RowSource = strbranch
Me.cbocredbranch.Requery

I'm trying to add; ORDER By [creditorbranch], after the where clause but it
keeps giving me error messages;

compile error: Line number or label or statement or end of statement

Help

"WHERE [creditorNameid] = " & Me!cbocreditor & " ORDER By
[creditorbranch];"

Note: the Value property is the default property. It is not necessary
to explicitly state it.
Also, I've assumed that the value of cboCreditor is a Number datatype,
not Text.
 
Hi Fredg
The combobox is based on a table but the values are srings (text). When I
enter the line of code as you proposed the second combobox is empty. There
are no error messages though.


fredg said:
Hi

I've got two comboboxes - one filtering the other. I would like the
filtered combo boxs' contents to be in Alphabetaical order.

Private Sub cboCreditor_AfterUpdate()
Dim strbranch As String

strbranch = "SELECT
[tblcreditoraddresses].[creditoraddressid],[tblcreditoraddresses].[creditorn
ameid], [tblcreditoraddresses].[creditorbranch]" & _
"FROM [tblcreditoraddresses] " & _
"WHERE [creditorNameid] = " & Me.cbocreditor.Value
Me.cbocredbranch.RowSource = strbranch
Me.cbocredbranch.Requery

I'm trying to add; ORDER By [creditorbranch], after the where clause but it
keeps giving me error messages;

compile error: Line number or label or statement or end of statement

Help

"WHERE [creditorNameid] = " & Me!cbocreditor & " ORDER By
[creditorbranch];"

Note: the Value property is the default property. It is not necessary
to explicitly state it.
Also, I've assumed that the value of cboCreditor is a Number datatype,
not Text.
 
Hi Fredg
The combobox is based on a table but the values are srings (text). When I
enter the line of code as you proposed the second combobox is empty. There
are no error messages though.

fredg said:
Hi

I've got two comboboxes - one filtering the other. I would like the
filtered combo boxs' contents to be in Alphabetaical order.

Private Sub cboCreditor_AfterUpdate()
Dim strbranch As String

strbranch = "SELECT
[tblcreditoraddresses].[creditoraddressid],[tblcreditoraddresses].[creditorn
ameid], [tblcreditoraddresses].[creditorbranch]" & _
"FROM [tblcreditoraddresses] " & _
"WHERE [creditorNameid] = " & Me.cbocreditor.Value
Me.cbocredbranch.RowSource = strbranch
Me.cbocredbranch.Requery

I'm trying to add; ORDER By [creditorbranch], after the where clause but it
keeps giving me error messages;

compile error: Line number or label or statement or end of statement

Help

"WHERE [creditorNameid] = " & Me!cbocreditor & " ORDER By
[creditorbranch];"

Note: the Value property is the default property. It is not necessary
to explicitly state it.
Also, I've assumed that the value of cboCreditor is a Number datatype,
not Text.

I qualified my response by stating that I assumed the value was Number
datatype (because that is how you had written it in your original
post).

If the bound column is text then:

"WHERE [creditorNameid] = '" & Me!cbocreditor & "' ORDER By
[creditorbranch];"

With spaces added for clarity the quotes above are:
= ' " & Me!cbocreditor & " ' ORDER By etc.
 
Back
Top