Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA 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 May 16th, 2006, 01:13 PM
Authorized User
 
Join Date: Oct 2005
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default ListBox.AddItem In Access 2000

Is there a way to do a listbox.additem in Access 2000 VBA??

 
Old May 16th, 2006, 01:19 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Hi Tready,

Not directly, but you can do it in a sneaky way. Below is a Sub I keep in a module for an App I converted from VB to VBA. Instead of doing lisMyBox.AddItem ("My Item"), call ListAddItem lisMyBox, "My Item"

Code:
Sub ListAddItem(LB As ListBox, ByVal strItemToAdd As String)
    If LB.RowSource = "" Then
        LB.RowSource = IIf(LB.RowSource = "", strItemToAdd, "")
    Else
        LB.RowSource = LB.RowSource & ";" & strItemToAdd
    End If
End Sub
Hope that helps,

Mike

Mike
EchoVue.com
 
Old May 16th, 2006, 01:32 PM
Authorized User
 
Join Date: Oct 2005
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thnx, that worked great.

 
Old August 17th, 2006, 01:11 PM
Registered User
 
Join Date: Aug 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Mike, there is a small problem with your code. You are saying LB.Rowsource="" twice in your code. I think you meant this:

Sub ListAddItem(LB As ListBox, ByVal strItemToAdd As String)
    If LB.RowSource = "" Then
        LB.RowSource = strItemToAdd
    Else
        LB.RowSource = LB.RowSource & ";" & strItemToAdd
    End If
End Sub

or maybe you were thinking about this one-liner:

Sub ListAddItem(LB As ListBox, ByVal strItemToAdd As String)
  LB.RowSource = IIf(LB.RowSource = "", strItemToAdd,LB.RowSource & ";" & strItemToAdd)
End Sub

you should also take the liberty of checking if RowSourceType="Value List" somewhere near the top of the routine.

Mario






Similar Threads
Thread Thread Starter Forum Replies Last Post
List box AddItem bogs down williamlove Access VBA 4 November 8th, 2008 11:46 PM
list10.column(0).additem? hah! Astro VB How-To 2 March 6th, 2007 03:51 AM
SQL SERVER 2000 AND ACCESS 2000 ckentebe SQL Server 2000 3 June 17th, 2004 08:50 PM
ADE file in Access 2000 <---> Access XP ginoitalo Access 3 April 14th, 2004 09:06 PM
Access XP VBA compatibility issues w/ Access 2000 bourgeois02 Access VBA 1 August 19th, 2003 04:14 PM





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