473,402 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

using listboxes

I need to pick up search results from a table and display them in a
listbox. I've made a simple 2-column listbox and the following code
returns "Object Required" on the Me.ListBox.Column(0,0) lines.

What's the solution?

Here's the code:

-- snip --

Private Sub SearchButton_Click()
Dim query As String, myDate As String, rs As Recordset

DateBox.SetFocus

query = "SELECT Through,Amount FROM ExpDaily WHERE Date=" &
DateBox.Text & ";"

MsgBox (query)
Set rs = CurrentDb.OpenRecordset(query)

If rs.RecordCount <> 1 Then
Me.ListBox.Column(0, 0) = "None"

Else
Me.ListBox.Column(0, 0) = rs!Through

End If
...
-- snip --

Apr 2 '06 #1
2 2325
na********@gmail.com wrote:
I need to pick up search results from a table and display them in a
listbox. I've made a simple 2-column listbox and the following code
returns "Object Required" on the Me.ListBox.Column(0,0) lines.

What's the solution?

Here's the code:

-- snip --

Private Sub SearchButton_Click()
Dim query As String, myDate As String, rs As Recordset

DateBox.SetFocus

query = "SELECT Through,Amount FROM ExpDaily WHERE Date=" &
DateBox.Text & ";"

MsgBox (query)
Set rs = CurrentDb.OpenRecordset(query)

If rs.RecordCount <> 1 Then
Me.ListBox.Column(0, 0) = "None"

Else
Me.ListBox.Column(0, 0) = rs!Through

End If
...
-- snip --

Back in A97 we'd create a UserDefined function to display items in
listboxes if the list were large (see RowSourceType and user-defined
function in that topic in help).

If the list is small, we could also type the values.
Me.ListBox.RowSource = "test;Test1;Test2"

In more recent versions I believe you can use AddItem/DeleteItem. But
I've never seen assigning a column value like the way you are doing it.

Most often people create a rowsource and then assign it.
strSQL = "Select EmpID, EmployeeName From Employee"
Me.ListBox0.Rowsource = strSQL
Apr 2 '06 #2
Unfortunately you can't set the value of a column of a listbox like
you're describing. If what you are trying to do is simply indicate
that no records were returned by your query you could do this with a
message box, e.g.

If rs.RecordCount = 0 Then
MsgBox "No records found."
Else
Set Me.ListBox.Recordset = rs!Through
End If

You could also bypass using a recordset altogether by setting the
rowsource property of your listbox and using the listcount property to
tell you how many rows were returned:

Me.ListBox.Rowsource = "SELECT Through,Amount FROM ExpDaily WHERE
Date=" &
DateBox.Text

If Me.ListBox.ListCount = 0 Then MsgBox "No records found."

Finally, you could simulate the behavior you're describing by placing a
hidden label with caption = "None" control on top of your listbox,
positioning it at the upper left corner of the listbox, and toggling
whether or not it is visible based on the number of records returned:

Me.ListBox.Rowsource = "SELECT Through,Amount FROM ExpDaily WHERE
Date=" &
DateBox.Text

If Me.ListBox.ListCount = 0 Then
lblMyHiddenLabel.Visible = True
Else
lblMyHiddenLabel.Visible = False
End If

Hope this helps,
Bruce

Apr 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jeffrey Barish | last post by:
I have an application that produces two listboxes. I would like to be able to select one of the items in the first listbox and one of the items in the second listbox. However, when I make my...
9
by: Megan | last post by:
Hi- I'm creating a database of music bands with their cds and songs. I'm trying to program an SQL statement so that I can enter a string of text in a textbox, press the 'Enter' key, and have...
9
by: Susan Bricker | last post by:
Hi. I have two questions ... (1) I want to use a Listbox to enable the user to select 1 or many items from the list. However, I'm having trouble figuring out how to find out t which items have...
4
by: bill yeager | last post by:
I have several template columns inside of a datagrid. Inside of these template columns are databound listboxes: <asp:TemplateColumn HeaderText="Crew Chiefs"> <ItemTemplate> <asp:listbox...
0
by: Terry D | last post by:
I'm having an issue with an ASP.NET page (VS.NET 2003, VB.NET, Oracle back end). The page uses the standard VS.NET grid to display the records from a particular table. The user can edit certain...
1
by: Ryan Ternier | last post by:
I have two listboxes, and allow users to move items between them via the following function: function SwitchList(fbox, tbox){ var arrFbox = new Array(); var arrTbox = new Array(); var...
0
by: Luis Esteban Valencia | last post by:
have a problem and I'm not sure how to handle/fix it. I have three listboxes on my page. The first listbox has a list of software products. When you select an item in the Products listbox, then...
0
by: koonda | last post by:
Hi guys, I posted a message before and I got some help from the forum. I have a database in SQL Server and I wanted to create a web interface in C#. I had 4 Listbox controls and a Textbox and two...
0
by: tarvold | last post by:
I am new to VBA and am trying to get this project done, so any help would be appreciated. I am trying to create a userform that will input the total hours worked by an employee into an excel...
5
by: Thelma Roslyn Lubkin | last post by:
I am still having trouble trying to use a popup form to allow user to set filters for the main form. The main form is based on a single table. The popup contains 5 listboxes, so the user can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.