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.
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... |
 |
|
dpwhitedp
Starting Member
5 Posts |
Posted - 2004-05-04 : 14:40:08
|
the listbox is not in the form.open.eventlistboxes seem to automitcally open with the form.Any more ideas are appreciated |
 |
|
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?MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
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 criteria2) Do some SQL3) Load the list boxSo you may have:Dim strSQL As StringstrSQL = "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 RecordsetDim db As DatabaseDim strSQL As StringstrSQL = "SELECT ProductName FROM Products WHERE Customer=' " & Me.txtSearch.Value & "' ORDER BY ProductName"Set db=CurrentdbSet rs=db.OpenRecordset(strSQL)if rs.bof then 'no recordselse while not rs.eof lstBox.AddItem(rs("ProductName").Value rs.MoveNext wend rs.close db.closeend ifset rs= nothingset db=nothing If you need more help post back.Jonwww.web-impulse.com |
 |
|
|
|
|