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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ListBox Selection

Status
Not open for further replies.

hubs99

Programmer
Jul 9, 2004
17
US
I am using a listbox to jump from record to record based on list of dates. However I want to add a few other features that I cant seem to figure out.


When A date is updated how can I update the listbox and have the proper date selected in the listbox?


Also I would like that when a new recorded is added the date is placed in the listbox and that particular date is selected?


Any help would be highly appreciated.
 
use a query in the list boxes row source then requery the form.
To make it select the correct date, use a query to find the dates position and put this in the default value property. Once again requery the form.



Ian Mayor (UK)
Program Error
There's ALWAYS more than one way to skin a cat!
But only one way to get it RIGHT!
 
How do you set the default value?

Where is the best place to find information on Comboboxes?
 
I know how to define a default in the form properties but I cant seem to set it on the fly. any advice?


Justin
 
Actually I do not know what Program Error is saying.

1) You definately do not want to requery the form. This will take you to the first record.
2) I have no idea what you want to do with the default value

Code:
Private Sub txtBxDate_AfterUpdate()
  Me.Recalc
  Me.cmboDate.value = Me.txtBxDate
  Me.cmboDate.Requery
End Sub

Assuming this is what you want to do, and assuming that the row source for the combo is something like

Code:
SELECT [tblDates].[date] FROM tblDates ORDER BY [tblDates].[date];

where [date] is the recordsource of txtBxDate.

This updates the combo, and selects the value.
 
Sorry about misleading you with the default value method, it was late when I replied.

If your listbox is based on a value list then play around with the additem and removeitem methods

Also I would like that when a new recorded is added the date is placed in the listbox and that particular date is selected?
If you tie this to a command button

DoCmd.GoToRecord , , acNewRec
Me.Listboxname.AddItem Item:=Str(Me.NewDateTXT)
Me.Listboxname.Value = Me.NewDateTXT

This will jump to a new record, add a date to the listbox if entered in textbox called newdateTXT

You may want to base the listbox on a separate table instead in which case all you need to do is add another record to the table and requery the listbox (not the form as mentioned before) then make the listbox value equal to the last record in the table.


Ian Mayor (UK)
Program Error
Programming is 10% coding and 90% error checking.
 
How are ya hubs99 . . .

I agree with [blue]ProgramError[/blue] on the use of a query for the row source. This allows you to update the listbox with [blue]newly saved[/blue] records/dates.

[blue]Newly saved[/blue] is the operative phrase here. Be aware: [purple]the listbox can only reaveal previously saved records[/purple](when using query/SQL as RowSource), which means when you enter the date [blue]you'd have to prematurely save the record for what you want to happen.[/blue]

Would this suite your needs (can be done)?

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top