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

MSForms Listbox Control is NULL

Status
Not open for further replies.

JTBorton

Technical User
Jun 9, 2008
345
DE
Access 2007
I am trying to set a property in my class module an MSForms listbox control (lstItemLinks) on my user form, but the listbox shows as null when I run the code. Why is the listbox NULL? It works fine when I code the list box from the form module. All of the other controls are access controls so they reference just fine. I would like to use an MSForm.ListBox instead of an Access.Listbox if it is possible.

Code:
    Set clsLinks = New clsLinkManager
    With clsLinks
        Set .tabMenu = tabLinks
        Set .cmdDelete = cmdDeleteLink
        Set .cmdOpen = cmdOpenLink
        Set .cmdNew = cmdNewLink
        Set .cmdLink = cmdLinkExisting
        [highlight]Set .lstLinks = lstItemLinks[/highlight] 
        Set .txtLinkID = txtLinkID
        Set .cboLinkType = cboLinkType
        .LoadControls
    End With

Code:
Public Property Get lstLinks() As CustomControl
    Set lstLinks = plstItems
End Property
[highlight]Public Property Set lstLinks(ListBox As CustomControl)[/highlight]
    Set plstItems = ListBox
End Property

Public Property Get cmdOpen() As Access.CommandButton
    Set cmdOpen = pcmdOpen
End Property
Public Property Set cmdOpen(CommandButton As Access.CommandButton)
    Set pcmdOpen = CommandButton
End Property

-Joshua
If it's not broken, it doesn't have enough parts yet.
 
This may be far-fetched, but it's what is coming to mind. Have you tried swapping out Global for Public when you're declaring the class items to see if that resolves the issue? Seems I've run into an issue once or twice where using Public (though seemed correct to me) did not work, but Global did. I realize there are specific reasons for 1 vs the other, but thought it worth a try to verify.

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
 
private plstItems as msforms.listbox

Public Property Get lstLinks() As msforms.listbox
Set lstLinks = plstItems.object
End Property
Public Property Set lstLinks(ListBox As msforms.listbox)
Set plstItems = ListBox.object
End Propert
 
kjv,

An interesting thought, but when I try to change the scope to global in the class module I get an error message saying that constants, fixed length strings, user defined types, bla bla bla, are not allowed as public variables in a class module. This is rather peculiar since I can declare the variable as Public, but not Global.

-Joshua
If it's not broken, it doesn't have enough parts yet.
 
MajP,

You would think you could declare it as an MSForms.Listbox variable, but that doesn't work in Access. In access even though you add an Active X MSForms Listbox control is is actually a CustomControl variable (which was a task in itself to figure out!).

-Joshua
If it's not broken, it doesn't have enough parts yet.
 
Figured it out. I had to declare the listbox variable as an Object instead of a CustomControl. It works, but I can no longer declare it WithEvents.

-Joshua
If it's not broken, it doesn't have enough parts yet.
 
You would think you could declare it as an MSForms.Listbox variable, but that doesn't work in Access. In access even though you add an Active X MSForms Listbox control is is actually a CustomControl variable (which was a task in itself to figure out!).
Do not know what you are talking about. As I show is correct and works fine.
 
Really? And you are adding the control by using the 'Active X Control' option form the form design menu and then selecting an MSForms Listbox? It doesn't seem to place a true MSForms.Listbox control on the form for me. It places an 'Access.CustomControl' object on the form instead of a real MSForms control. I wonder what I am doing different??

-Joshua
If it's not broken, it doesn't have enough parts yet.
 
I honestly have no idea what you are talking about with the customcontrol property. Can you provide a link, I do not believe it is correct? The following works fine, and traps the events.

Code:
'class MSListDemo

Private WithEvents msLst As MSForms.ListBox

Public Property Get MSlistBox() As MSForms.ListBox
  Set MSlistBox = msLst
End Property

Public Property Let MSlistBox(ByVal lstBx As MSForms.ListBox)
   Set msLst = lstBx
End Property

Private Sub msLst_Change()
  MsgBox msLst.Value
End Sub

from the form
Code:
Private msld As New MSListDemo

Private Sub Form_Load()
  msld.MSlistBox = Me.msLstBoxOne.Object
  LoadList
End Sub

Public Sub LoadList()
  Me.msLstBoxOne.Object.AddItem "test"
  Me.msLstBoxOne.Object.AddItem "Test 2"
End Sub

When I add a MSForm object from the designer it is an actual MSForm object in the property sheet
OLE CLass : Microsoft Forms 2.0
Class : Forms.ListBox.1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top