Strange Userform Error

AndrewKent

Well-known Member
Joined
Jul 26, 2006
Messages
889
I'm having a bit of an issue with two userforms.

I have a workbook containing quite a few userforms in it, each that has an initialize routine calling different private macros specific to them.

Problem is that I have one userform with one macro that is being called anytime I launch ANY userform??? It's very strange.

What could be causing this?
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
If it's also helpful,

each userform has a Private "Sub UserForm_Initialize()" routine that is carried out on opening.
 
Upvote 0
Without looking at your vba project its near impossible to say what is causing that. To give us a starting point - what is the sub that ALWAYS fires called?
 
Upvote 0
Okay sorry guys for being so vauge...

I found the macro that is causing the problem...

Code:
Sub LoadConversation()

'   =============================================================================================
'   This macro will load up the conversation anytime there is a change in multipages or
'   userforms.
'   =============================================================================================

    Dim Brand As String

    Brand = Worksheets("Data Capture").Range("C11").Value

    frmInboundIntro.txtFPDirect11.Value = Worksheets("Conversation").Range("G69").Value
    frmInboundIntro.txtCustomerDirect1.Value = Worksheets("Conversation").Range("G59").Value
    frmInboundIntro.txtStakeholder1.Value = Worksheets("Conversation").Range("G41").Value
    frmInboundIntro.txtStakeholder21.Value = Worksheets("Conversation").Range("G50").Value
    frmInboundIntro.txtStakeholder22.Value = Worksheets("Conversation").Range("G52").Value
    frmInboundIntro.txtOutbound11.Value = Worksheets("Conversation").Range("G18").Value
    frmInboundIntro.txtOutbound12.Value = Worksheets("Conversation").Range("G20").Value
    frmInboundIntro.txtOutbound21.Value = Worksheets("Conversation").Range("G23").Value
    frmFunnel.txtMandatory1.Value = Worksheets("Conversation").Range("G113").Value
    frmPersonalDetails.txtPersonalDetails11.Value = Worksheets("Conversation").Range("G215").Value
    frmCallClose.txtCallClose1.Value = Worksheets("Conversation").Range("G243").Value
    frmCallClose.txtCallClose3.Value = Worksheets("Conversation").Range("G248").Value
    frmCallClose.txtCallClose4.Value = Worksheets("Conversation").Range("G250").Value
    frmCallClose.txtCallClose5.Value = Worksheets("Conversation").Range("G252").Value
    frmCallClose.txtClose5.Value = Worksheets("Conversation").Range("G235").Value
    frmGCB3.txtSourceOfFunds1.Value = Worksheets("Conversation").Range("G259").Value
    frmTFDirectInvestment.txtSourceOfFunds1.Value = Worksheets("Conversation").Range("G259").Value
    frmTFISA.txtSourceOfFunds1.Value = Worksheets("Conversation").Range("G259").Value
    frmCombiBond.txtSourceOfFunds1.Value = Worksheets("Conversation").Range("G259").Value

    frmPersonalDetails.lblCustomer1.Caption = "Are you an existing " & Brand & " customer?"

    frmInboundIntro.txtOutbound27.Value = Worksheets("Calculation Matrix").Range("CalculationMatrix_C1FullName").Value

End Sub

...this is being called on initializing EVERY userform...I think I've f*cked up here in that by loading the conversation into each of these labels, it is infact opening ALL the userforms mentioned here?
 
Upvote 0
Just as a quick fix,

at the top of your module (not forms) the place where you have your subs, put
Code:
Global RunFormIntProcess As Boolean
Then at the start of your initialize events on your userforms put the code
Code:
if RunFormIntProcess = true then exit sub
Then at the start of your sub put
Code:
RunFormIntProcess = true
and at the end of your sub put
Code:
RunFormIntProcess = false
What this will do is make sure the other forms dont initialize while your running the sub

hope this makes sence

Cheers
GB
 
Upvote 0
I think I've f*cked up here in that by loading the conversation into each of these labels, it is infact opening ALL the userforms mentioned here?

That is correct. As soon as you refer to a userform, you load an instance of it. So in actual fact, the forms are not calling the sub, it is calling them by the looks of it.
 
Upvote 0
Right, quick update to the LoadConversation routine and it now works fine...

Code:
Sub LoadConversation()

'   =============================================================================================
'   This macro will load up the conversation anytime there is a change in multipages or
'   userforms.
'   =============================================================================================

    Dim Brand As String

    Brand = Worksheets("Data Capture").Range("C11").Value

    If Worksheets("Calculation Matrix").Range("CalculationMatrix_CurrentUserform").Value = "frmInboundIntro" Then
        frmInboundIntro.txtFPDirect11.Value = Worksheets("Conversation").Range("G69").Value
        frmInboundIntro.txtCustomerDirect1.Value = Worksheets("Conversation").Range("G59").Value
        frmInboundIntro.txtStakeholder1.Value = Worksheets("Conversation").Range("G41").Value
        frmInboundIntro.txtStakeholder21.Value = Worksheets("Conversation").Range("G50").Value
        frmInboundIntro.txtStakeholder22.Value = Worksheets("Conversation").Range("G52").Value
        frmInboundIntro.txtOutbound11.Value = Worksheets("Conversation").Range("G18").Value
        frmInboundIntro.txtOutbound12.Value = Worksheets("Conversation").Range("G20").Value
        frmInboundIntro.txtOutbound21.Value = Worksheets("Conversation").Range("G23").Value
        frmInboundIntro.txtOutbound27.Value = Worksheets("Calculation Matrix").Range("CalculationMatrix_C1FullName").Value
        Exit Sub
    End If
    
    If Worksheets("Calculation Matrix").Range("CalculationMatrix_CurrentUserform").Value = "frmFunnel" Then
        frmFunnel.txtMandatory1.Value = Worksheets("Conversation").Range("G113").Value
        Exit Sub
    End If
    
    If Worksheets("Calculation Matrix").Range("CalculationMatrix_CurrentUserform").Value = "frmInboundIntro" Then
        frmPersonalDetails.txtPersonalDetails11.Value = Worksheets("Conversation").Range("G215").Value
        frmPersonalDetails.lblCustomer1.Caption = "Are you an existing " & Brand & " customer?"
        Exit Sub
    End If
    
    If Worksheets("Calculation Matrix").Range("CalculationMatrix_CurrentUserform").Value = "frmCallClose" Then
        frmCallClose.txtCallClose1.Value = Worksheets("Conversation").Range("G243").Value
        frmCallClose.txtCallClose3.Value = Worksheets("Conversation").Range("G248").Value
        frmCallClose.txtCallClose4.Value = Worksheets("Conversation").Range("G250").Value
        frmCallClose.txtCallClose5.Value = Worksheets("Conversation").Range("G252").Value
        frmCallClose.txtClose5.Value = Worksheets("Conversation").Range("G235").Value
        Exit Sub
    End If
    
    If Worksheets("Calculation Matrix").Range("CalculationMatrix_CurrentUserform").Value = "frmGCB3" Then
        frmGCB3.txtSourceOfFunds1.Value = Worksheets("Conversation").Range("G259").Value
        Exit Sub
    End If
    
    If Worksheets("Calculation Matrix").Range("CalculationMatrix_CurrentUserform").Value = "frmTFDirectInvestment" Then
        frmTFDirectInvestment.txtSourceOfFunds1.Value = Worksheets("Conversation").Range("G259").Value
        Exit Sub
    End If
    
    If Worksheets("Calculation Matrix").Range("CalculationMatrix_CurrentUserform").Value = "frmTFISA" Then
        frmTFISA.txtSourceOfFunds1.Value = Worksheets("Conversation").Range("G259").Value
        Exit Sub
    End If
    
    If Worksheets("Calculation Matrix").Range("CalculationMatrix_CurrentUserform").Value = "frmCombiBond" Then
        frmCombiBond.txtSourceOfFunds1.Value = Worksheets("Conversation").Range("G259").Value
        Exit Sub
    End If

End Sub

...it now only loads what it needs.

Cheers for the help guys!
 
Upvote 0
Wouldn't it make more sense to pass a value directly to the LoadConversation routine so it knows what it's updating, rather than having it read a worksheet cell?
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,698
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top