Synchronize Combo box with radio buttons using vba

  • Follow


Hi,

I have following code behind one of my unbound combo box:

Dim StrSql As String
strSql = "SELECT tblCustomer.CustomerCode, tblCustomer.CustomerName,
tblCustomer.BillingAddress " & vbCrLf & _
"FROM tblCustomer;"
    Me.cmbfind.RowSourceType = "Table/Query"
    Me.cmbfind.RowSource = StrSql
    Me.cmbfind.ColumnHeads = True
    Me.cmbfind.ColumnCount = 3
    Me.cmbfind.ColumnWidths = "1 in;2 in;.95 in"
    Me.cmbfind.ListWidth = 4

I have also 3 radio buttons on my form

1. CustomerCode

2. CustomerName

3. BillingAddress

I want that when I click no. 1 radio button combo box shows 3 columns
as

customer code > CustomerName > BillingAddress

when I click no. 2 radio button combo box shows 3 columns as

CustomerName > customer code > BillingAddress and so on, means my
combo box columns moves according to my choice I have already program
my radio buttons, how I do this usin vba
p.s I am not willing to use multiple select statements behind each
radio button
0
Reply Shakeel 11/18/2010 3:07:43 PM

Shakeel wrote:

> Hi,
> 
> I have following code behind one of my unbound combo box:
> 
> Dim StrSql As String
> strSql = "SELECT tblCustomer.CustomerCode, tblCustomer.CustomerName,
> tblCustomer.BillingAddress " & vbCrLf & _
> "FROM tblCustomer;"
>     Me.cmbfind.RowSourceType = "Table/Query"
>     Me.cmbfind.RowSource = StrSql
>     Me.cmbfind.ColumnHeads = True
>     Me.cmbfind.ColumnCount = 3
>     Me.cmbfind.ColumnWidths = "1 in;2 in;.95 in"
>     Me.cmbfind.ListWidth = 4
> 
> I have also 3 radio buttons on my form
> 
> 1. CustomerCode
> 
> 2. CustomerName
> 
> 3. BillingAddress
> 
> I want that when I click no. 1 radio button combo box shows 3 columns
> as
> 
> customer code > CustomerName > BillingAddress
> 
> when I click no. 2 radio button combo box shows 3 columns as
> 
> CustomerName > customer code > BillingAddress and so on, means my
> combo box columns moves according to my choice I have already program
> my radio buttons, how I do this usin vba
> p.s I am not willing to use multiple select statements behind each
> radio button

Well, you could set the column count to 4 and set the column width to 0 
on the column you don't want to display.  If you can handle the order of 
the field display; Code for 1, custname for 2, address for 3 as the 
first column why not simply change the SQL statement.  Otherwise you 
might have to change the bound column property as well.
0
Reply Salad 11/18/2010 4:16:34 PM


On Nov 18, 10:07=A0am, Shakeel <shakeel....@gmail.com> wrote:
> Hi,
>
> I have following code behind one of my unbound combo box:
>
> Dim StrSql As String
> strSql =3D "SELECT tblCustomer.CustomerCode, tblCustomer.CustomerName,
> tblCustomer.BillingAddress " & vbCrLf & _
> "FROM tblCustomer;"
> =A0 =A0 Me.cmbfind.RowSourceType =3D "Table/Query"
> =A0 =A0 Me.cmbfind.RowSource =3D StrSql
> =A0 =A0 Me.cmbfind.ColumnHeads =3D True
> =A0 =A0 Me.cmbfind.ColumnCount =3D 3
> =A0 =A0 Me.cmbfind.ColumnWidths =3D "1 in;2 in;.95 in"
> =A0 =A0 Me.cmbfind.ListWidth =3D 4
>
> I have also 3 radio buttons on my form
>
> 1. CustomerCode
>
> 2. CustomerName
>
> 3. BillingAddress
>
> I want that when I click no. 1 radio button combo box shows 3 columns
> as
>
> customer code > CustomerName > BillingAddress
>
> when I click no. 2 radio button combo box shows 3 columns as
>
> CustomerName > customer code > BillingAddress and so on, means my
> combo box columns moves according to my choice I have already program
> my radio buttons, how I do this usin vba
> p.s I am not willing to use multiple select statements behind each
> radio button

if your radio buttons are radio buttons of a Group control then in the
On-click event of the Group control you can set up Select Case logic
to do this.
sample;

Dim StrSql As String
Select Case YourGroupControlName
Case 1   'customer code first
 strSql =3D "SELECT tblCustomer.CustomerCode, tblCustomer.CustomerName,
 tblCustomer.BillingAddress " & vbCrLf & _
 "FROM tblCustomer;"
Me.cmbfind.ColumnWidths =3D "1 in;2 in;.95 in"

Case 2    'customer name first
 strSql =3D "SELECT tblCustomer.CustomerName, tblCustomer.CustomerCode,
 tblCustomer.BillingAddress " & vbCrLf & _
 "FROM tblCustomer;"
Me.cmbfind.ColumnWidths =3D "2 in;1 in;.95 in"

Case 3    'customer billing address first
 strSql =3D "SELECT tblCustomer.BillingAddress,
tblCustomer.CustomerName,
 tblCustomer.CustomerCode" & vbCrLf & _
 "FROM tblCustomer;"
Me.cmbfind.ColumnWidths =3D "0.95 in;1 in;2 in"

End Select

 Me.cmbfind.RowSourceType =3D "Table/Query"
 Me.cmbfind.RowSource =3D StrSql
 Me.cmbfind.ColumnHeads =3D True
 Me.cmbfind.ColumnCount =3D 3
 Me.cmbfind.ColumnWidths =3D "1 in;2 in;.95 in"
 Me.cmbfind.ListWidth =3D 4
' then do whatever you do next

bobh.
0
Reply bobh 11/19/2010 6:58:46 PM

2 Replies
677 Views

(page loaded in 0.05 seconds)

Similiar Articles:













7/19/2012 4:35:54 PM


Reply: