Error passing Form to module

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
1,835
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Excel seems to allow a Userform to be passed to Sub MCF in module1 but it doesn't work as expected
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
   If Target.row > 1 Then
        Cancel = True
        Select Case Target.Column
            Case 3
                MCF SelRow, frmSerial
            End Select
    End If
End Sub


Sub MCF(SelRow As Range, fMain As UserForm)
    fMain.show      
    With SelRow
        fMain.Caption = "ThisCaption"
    End With
End sub

The command fMain.Caption doesn't print in the Caption area but on the Form itself, and fMain.show errors with Object doesn't support this property or method
What am I doing wrong ? The reason for passing the Form itself to the module (which creates some controls at run time), is so they can be created for whichever form is pased in. Or so is hoped.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi,
try these changes to your code & see if they do what you wat

Sheet code page

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

   If Target.Row > 1 Then
        Cancel = True
        Select Case Target.Column
            Case 3
                MCF Target, frmSerial
            End Select
    End If
End Sub

Standard Module

VBA Code:
Sub MCF(ByVal SelRow As Range, ByVal fMain As Object)
    
    fMain.Caption = "ThisCaption"
    
    fMain.Show

End Sub

Dave
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,545
Members
449,089
Latest member
davidcom

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