Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

assigning defaults to list control

Status
Not open for further replies.

jjd100

Programmer
May 30, 2005
19
CA
I am having trouble assigning a default value to a list box control that I have which contains two columns.

The code I am using in the form_open is as follows:

strsql = " SELECT ltp_nme, ltp "
strsql = strsql & " FROM ltp "
strsql = strsql & " WHERE YEAR = " & iYear
strsql = strsql & " ORDER BY ltp desc"

chart_LTP.RowSourceType = "Table/Query"
chart_LTP.RowSource = strsql

chart_LTP = chart_LTP.Column(0, 0) + ";" + chart_LTP.Column(1, 0)


The chart_LTP control is assigned the values correctly when I go throught the debugger, but they do not display on the form (it is blank). For a single column list box I am having no problems, but this has two columns, the column count is 2 and the bound column is 2.

I can select the values in the list box with no problems, it's just the default that isn't showing up.

Any ideas would be greatly appreciated.
 
First, I'd use the Load event instead of the Open.
Second, replace this:
chart_LTP = chart_LTP.Column(0, 0) + ";" + chart_LTP.Column(1, 0)
with this:
Me!chart_LTP.SetFocus
Me!chart_LTP.ListIndex = 0

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I tried that and it didn't work, I got the message "You've used the listindex property incorrectly".
The good news is that I did some more reading and then figured out that I only need to assign the bound column to the listbox when assigning a default, not both columns, which in hindsight now seems obvious.
To pick the first row as a default value for the list box with a bound column of 2 the following worked correctly:
chart_LTP = chart_LTP.Column(1, 0)
 
Why not:

[tt]Me.chart_LTP.Selected(0) = True[/tt]

?
 
I get:
Compile Error: Method or data member not found.

the compiler does not like the word ".Selected(0)
 
Which version of Access are you using?
 
AC2003 ?
So, please, could you post the EXACT code raising the following error ?
You've used the listindex property incorrectly

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
here is the function in its entirety:

Code:
Private Function PopulateLTP(iYear As Integer) As Boolean
' 29b: LY 20070417 populate the chart_LTP combo box
On Error GoTo Err_PopulateLTP
    Dim strsql As String
    strsql = " SELECT ltp_nme, ltp "
    strsql = strsql & "  FROM ltp "
    strsql = strsql & " WHERE YEAR = " & iYear
    strsql = strsql & " ORDER BY ltp desc"

    Me.chart_LTP.RowSourceType = "Table/Query"
    Me.chart_LTP.RowSource = strsql
    
    ' comment out the following line that works correctly to try an alternate strategy suggested in tek-tips:
    'chart_LTP = chart_LTP.Column(1, 0)
    Me.chart_LTP.Selected(0) = True

    PopulateLTP = True
    
Exit_PopulateLTP:
    Exit Function

Err_PopulateLTP:
    MsgBox Err.Description
    PopulateLTP = False
    Resume Exit_PopulateLTP
End Function
 
What about replacing this:
Me.chart_LTP.Selected(0) = True
with this ?
Me!chart_LTP.SetFocus
Me.chart_LTP.ListIndex = 0

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I don't really want to give this control the focus, it causes other problems.
The solution
Code:
chart_LTP = chart_LTP.Column(1, 0)
of June 29 to assign the first item in a list box as the default works perfectly in this application and I'll be going with that, thanks everyone for your assistance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top