Guten Morgen,
du rufst lediglich die .add Methode falsch auf - ich habe zum Test noch eine neue Methode der Klasse cUserContainerhinzugefügt:
Klasse cUserContainer:
Option Explicit
Public strUser As String
Public strFolder As String
'Enthält alle momoReports des Users
Public colReports As Collection
'Es brauch eine Klasse mit usernamen, ordner, [dateinamen,jahr, monat]
Public Property Get GetUser()
GetUser = strUser
End Property
Public Property Let SetUser(pUser As String)
strUser = pUser
End Property
Public Property Get GetFolder()
GetFolder = strFolder
End Property
Public Property Let SetFolder(pFolder As String)
strFolder = pFolder
End Property
Public Sub AddReport(ByRef pReport As cReport)
If colReports Is Nothing Then Set colReports = New Collection
colReports.Add pReport
End Sub
Public Sub get_all_reports()
Dim i As cReport
For Each i In colReports
Debug.Print i.GetFilename
Debug.Print vbTab & i.GetMonth
Debug.Print vbTab & i.GetYear
Next i
End Sub
Klasse cReport:
Option Explicit
Private strFileName As String
Private intYear As Integer
Private intMonth As Integer
Public Sub Init(pFilename As String, pYear As Integer, pMonth As Integer)
strFileName = pFilename
intYear = pYear
intMonth = pMonth
End Sub
Public Property Let SetFilename(pFilename As String)
strFileName = pFilename
End Property
Public Property Get GetFilename() As String
GetFilename = strFileName
End Property
Public Property Let SetYear(pYear As Integer)
intYear = pYear
End Property
Public Property Get GetYear() As Integer
GetYear = intYear
End Property
Public Property Let SetMonth(pMonth As Integer)
intMonth = pMonth
End Property
Public Property Get GetMonth() As Integer
GetMonth = intMonth
End Property
Der Aufruf in einem Modul:
Option Explicit
Private Sub test()
Dim cont As cUserContainer
Dim rep As cReport
Set cont = New cUserContainer
Set rep = New cReport
Call rep.Init("derDateiName", 2015, 12)
Debug.Print rep.GetYear
Debug.Print rep.GetMonth
'Bei der folgenden Zeile wird der Fehler gemeldet...
Call cont.AddReport(rep)
Call cont.get_all_reports
End Sub
Gruß
|