Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Problem assigning a query to a list box dynamically

Discussion in 'Information Technology' started by Michael Ryle, Jul 28, 2006.

  1. Michael Ryle

    Michael Ryle
    Expand Collapse
    Guest

    I have a list box defined on a form and I call it "QueryResults".

    I want to be able to use VBA code to dynamically associate a query with this
    "QueryResults" list box control.

    So I write the following VBA code:

    Me.QueryResults.RowSource = "SELECT A, B, C from MyTable WHERE MyTable.A =
    'Some Value'"
    Me.QueryResults.RowSourceType = "Table/Query"
    Me.QueryResults.ColumnCount = "3"
    Me.QueryResults.ColumnHeads = True
    Me.QueryResults.ColumnWidths = "1;1;1;"
    Me.QueryResults.BoundColumn = "0"

    Next I assign the VBA code to a button control so that whenever I click on
    the button the query specified in "RowSource" above will run and the results
    will appear in the list box.

    The problem I'm running into is that what winds up in "QueryResults" after
    the query runs is always and only the last column, column C. No matter how I
    structure the query, I only get one column back and it's always the last one.

    Anybody know what gives here? Thanks.
     
  2. Loading...

    Similar Threads Forum Date
    Sikh News Sikhs Face Problems While Carrying Kirpans In Khyber-Pakhtunkhwa - SikhSiyasat.Net Breaking News Jul 29, 2016
    "Dasam" Granth - A Look At The Core Problems Dasam Granth Oct 21, 2015
    Problems In Life Sikh Sikhi Sikhism Apr 13, 2015
    How can I make decent and useful friends and from where ?? most people have a problem with me Sikh Youth Oct 23, 2013
    The Problem with Taking Too Many Vitamins Health & Nutrition Oct 18, 2013

  3. Michael Ryle

    Michael Ryle
    Expand Collapse
    Guest

    Never mind. I found the solution. Turns out that my column widths were not
    being recognized. This doesn't explain why only the last column was
    appearing. That, however, was a red herring.

    "Michael Ryle" wrote:

    > I have a list box defined on a form and I call it "QueryResults".
    >
    > I want to be able to use VBA code to dynamically associate a query with this
    > "QueryResults" list box control.
    >
    > So I write the following VBA code:
    >
    > Me.QueryResults.RowSource = "SELECT A, B, C from MyTable WHERE MyTable.A =
    > 'Some Value'"
    > Me.QueryResults.RowSourceType = "Table/Query"
    > Me.QueryResults.ColumnCount = "3"
    > Me.QueryResults.ColumnHeads = True
    > Me.QueryResults.ColumnWidths = "1;1;1;"
    > Me.QueryResults.BoundColumn = "0"
    >
    > Next I assign the VBA code to a button control so that whenever I click on
    > the button the query specified in "RowSource" above will run and the results
    > will appear in the list box.
    >
    > The problem I'm running into is that what winds up in "QueryResults" after
    > the query runs is always and only the last column, column C. No matter how I
    > structure the query, I only get one column back and it's always the last one.
    >
    > Anybody know what gives here? Thanks.
     

Share This Page