Class Module Function Running Twice

  • Thread starter RexAbandon via AccessMonster.com
  • Start date
R

RexAbandon via AccessMonster.com

I came across this situation and I hoping someone can help me with the
correct coding. I have simplified my project to make it easy to debug.

I have a main form (frmMain) that has a subform (frmSubForm). The main form
has the following code:

Option Compare Database
Option Explicit

Public test As clsTest

Private Sub Form_Open(Cancel As Integer)
Set test = New clsTest
test.MessageText = "This is the message"
test.SetupButtons
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set test = Nothing
End Sub


The subform contains two command buttons (btnCommand1 and btnCommand2) and
has following code:

Option Compare Database
Option Explicit

Public Function OpenItem()
MsgBox Me.Parent.test.MessageText
End Function


There is class module called clsTest and it contains the following code:

Option Compare Database
Option Explicit

Private m_MessageText As String

Public Property Get MessageText() As String
MessageText = m_MessageText
End Property

Public Property Let MessageText(ByVal strMessageText As String)
m_MessageText = strMessageText
End Property

Public Function SetupButtons()
With Forms("frmMain").Controls("frmSubForm").Form
.Controls("btnCommand1").OnClick = "=OpenItem()"
.Controls("btnCommand2").OnClick = "=parent.test.OpenItm(1)"
End With
End Function

Public Function OpenItm(i As Integer)
MsgBox MessageText
End Function


When btnCommand1 is clicked the function in the subform runs once. When
btnCommand2 is clicked the function in the Class Module runs twice. Can
somebody tell me why? Is there a work around? I prefer to run the function
in the class module.

Also, I had to include the argument (i as Integer) for OpenItm in the class
module. Error 2431 occurred when loading.

Thanks in advance,

Rex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top