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

List Box -- Add Item 2

Status
Not open for further replies.

LarryDeLaruelle

Technical User
May 19, 2000
1,055
US
Is it possible to create a list box's contents in code?

I would like to use an On_Load or On_Open event to populate a list box with the values I need instead of using the Row Source property in design view.

VBA does not have an AddItem (as VB does) so I tried setting the value of the row source in code as:

lstTest.RowSource = "one; two"

Doesn't work.

Is it possible? I would appreciate any suggestions.

Thanks.
Larry De Laruelle
larry1de@yahoo.com

 
Hi Larry!
This will do it:

Private Sub Form_Open(Cancel As Integer)
Me.YourListBox.RowSourceType = "Value List"
Me.YourListBox.RowSource = "'one thing';'another thing';'one other thing'"
End Sub

I specifically tell the listbox row source type to be a "value list" (optional) just in case it is originally something else... :) Gord
ghubbell@total.net
 
Gord:

Thank you very much.

That is pretty much what I had tried except I had put it in the On_Load event and had not explicitly set the type to Value List (although I had set that is the properties).

Any reason why this won't work in the On_Load? Perhaps because I'm opening it from design view?

Any color tips for this one?

Thanks again.
Larry De Laruelle
larry1de@yahoo.com

 
Hi Larry and thanks again...:) It should have worked in either event.. Maybe just a misplaced "little quote". The explicit type as well is a real option. I tell you (no one wants to believe me), its the Access Gremlins again!
I'll dream up a new color trick for tomorrow. I'll try and use our favorite in some elaborate equation... LOL

Gord
ghubbell@total.net
 
Well Larry, I couldn't wait:

any form you have or dare to insult:

Timer Interval: 1000 for one second (play with it for greater or less obnoxious effect...)

On Timer (event procedure):
Dim varColor
varColor = ((100002 * Rnd) + 10005 / (3 * Rnd))
Me.Detail.BackColor = varColor

What astounded me fiddling with this was the importance of the base numbers: not that 100002 is different from 100000 but if you select a lower number,say, 10000, your color range seems to always be in the darker end.

Might want to grab the Alka-Seltzer before. LOL Gord
ghubbell@total.net
 
Gord - me again! I thought this thread was great so ive been having a go at trying to sort out my user/time/date logging. But failed!

I have tried to enter this code, bearing in mind what this thread has been discussing, i thought that i could get it right. But its not really working, and i dont think its going to work in the way i want it to. I.e. its just a seperate for that record and i cannot get it to come up with say a datasheet format showing the records, who has vreateed them, when, who has editied them and when.

This is the code


Private Sub CreatedByUser_AfterUpdate()

Me![ModifiedBy] = CurrentUser()
Me![DateModified] = Now()

End Sub

Private Sub CreatedByUser_BeforeUpdate(Cancel As Integer)

Me![CreatedBy] = CurrentUser()
Me![DateCreated] = Now()

End Sub


do you think it would be best for me to try this in a subform?

sorry gord. i seem to be forever asking you questions!! Thank you for your help already.

Matt Pearcey
 
"bearing in mind what this thread has been discussing, i thought that i could get it right." ????

Good morning Matt.
I tell you what. You copy your post and add it to the right thread and I give it a go! (I know the one you're talking about) but doing anything off of this thread's subject is not going to help you and I in the future! Thanks Matt, :) Gord
ghubbell@total.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top