Wrox Programmer Forums
|
BOOK: Access 2010 VBA Programmer's Reference
This is the forum to discuss the Wrox book Access 2010 Programmer's Reference by Teresa Hennig, Rob Cooper, Geoffrey L. Griffith, Jerry Dennison; ISBN: 978-0-470-59166-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Access 2010 VBA Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 28th, 2012, 06:53 PM
Authorized User
 
Join Date: Jun 2006
Posts: 73
Thanks: 1
Thanked 1 Time in 1 Post
Default How Do Iuse 'AddItem' method on Form_Load event ?@

I can't seem to populate a combo box, using a FOR loop when loading a form ...
Here's the code ....

Private Sub Form_Load()
Dim cy As String
cy = DatePart("yyyy", Date)
For i = 0 To 4
cmbYear.AddItem(cy, i)
Next i
End Sub



I know ... if it works as it should, I would get 5 items in list of "2012", but that's fine for now. I'll do some arithmetic on the 'years' once I get it working.

The form loads, and prompts me to add the items individually 'on' the form at Run-time ??
 
Old April 29th, 2012, 11:31 AM
Authorized User
 
Join Date: Oct 2010
Posts: 64
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Hi liamfitz,

This will get you what you want (providing you want the list in descending order):

HTML Code:
Private Sub Form_Load()
    Dim cy As Integer
    Dim i As Integer
    cy = Year(Date)
    For i = 0 To 4
         Me.yearCombo.AddItem (CStr(cy - i))
    Next i
End Sub
HTH.

Malc.

Last edited by malcolmdixon; April 29th, 2012 at 11:33 AM..
 
Old April 30th, 2012, 08:43 AM
Authorized User
 
Join Date: Jun 2006
Posts: 73
Thanks: 1
Thanked 1 Time in 1 Post
Default How Do Iuse 'AddItem' method on Form_Load event ?

Mnay tahnks, that works just fine ! .... ( I ahd done it in the meantime, but it's right. )





Similar Threads
Thread Thread Starter Forum Replies Last Post
List box AddItem bogs down williamlove Access VBA 4 November 8th, 2008 11:46 PM
working with DLL event, method in JavaScript hendyhanusin Javascript How-To 0 March 23rd, 2007 05:12 AM
working with DLL event, method in JavaScript hendyhanusin Javascript 0 March 23rd, 2007 04:54 AM
ListBox.AddItem In Access 2000 tready Access VBA 3 August 17th, 2006 01:11 PM
newbie question on form_load rahzan Access VBA 5 April 15th, 2005 01:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.