Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 list boxes

Author  Topic 

dpwhitedp
Starting Member

5 Posts

Posted - 2004-05-04 : 13:46:27
I have a listbox on a form.
I have a text box where I enter a value and a button
that requery's the listbox to get the data. It works OK.
The problem is that when the form is opened the listbox
tries to initialize.
Locked and enable do not solve the problem.
How do I stop the list box from trying to initialize when the form
is openned.
thanks

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2004-05-04 : 14:01:49
Take the code out of the form.open event and just add it into the text box's change or after update event...
Go to Top of Page

dpwhitedp
Starting Member

5 Posts

Posted - 2004-05-04 : 14:40:08
the listbox is not in the form.open.event
listboxes seem to automitcally open with the form.
Any more ideas are appreciated
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-05-04 : 21:37:13
Can't you just set the datasource on the field to nothing? The first time you hit your button, you will need to then populate the source?

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

jhermiz

3564 Posts

Posted - 2004-05-27 : 23:07:15
quote:
Originally posted by dpwhitedp

I have a listbox on a form.
I have a text box where I enter a value and a button
that requery's the listbox to get the data. It works OK.
The problem is that when the form is opened the listbox
tries to initialize.
Locked and enable do not solve the problem.
How do I stop the list box from trying to initialize when the form
is openned.
thanks




Make sure the record source property of your list box is not a table or query. You basically will be dealing with a dummy or empty list box.

What you can do is load the data dynamically.

For instance:

1) Enter your search criteria
2) Do some SQL
3) Load the list box

So you may have:


Dim strSQL As String
strSQL = "SELECT ProductName FROM Products WHERE Customer=' " & Me.txtSearch.Value & "' ORDER BY ProductName"
Me.lstBox.Recordsource= strSQL


just make sure you reset the recordsource and redo it for each search (on click event). You can also take advantage of the on change event of the text box in case the search changes.

You also could use recordsets and the .AddListItem method to add individiual elements to the list box.


Dim rs As Recordset
Dim db As Database
Dim strSQL As String

strSQL = "SELECT ProductName FROM Products WHERE Customer=' " & Me.txtSearch.Value & "' ORDER BY ProductName"

Set db=Currentdb
Set rs=db.OpenRecordset(strSQL)

if rs.bof then
'no records
else
while not rs.eof
lstBox.AddItem(rs("ProductName").Value
rs.MoveNext
wend
rs.close
db.close
end if

set rs= nothing
set db=nothing


If you need more help post back.


Jon
www.web-impulse.com
Go to Top of Page
   

- Advertisement -