新VBA-er ...... 尝试初始化用户表单并使用来自两个主要用户表单之一的值填充字段。两个主要用户表单都具有相同的列表框,具有相同的列数,并且这些列中的数据相同。理想情况下,我想调用userform3并引用userform1或userform2。
领先的userform1:
Private Sub btEditAppt_Click()
fmEditAppt.UserForm_Initialize (Me)
End Sub
OR领先userform2(按钮名称相同):
Private Sub btEditAppt_Click()
fmEditAppt.UserForm_Initialize (Me)
End Sub
调用userform3:
Public Sub UserForm_Initialize(formFORM As UserForm)
Me.lbSerial = Format(formFORM.listAppts.Column(0), "0000")
Me.lbPSerial = Format(formFORM.listAppts.Column(1), "0000")
Me.tbApptDate = Format(formFORM.listAppts.Column(2), "MM/DD/YYYY")
Me.lbFirst = formFORM.listAppts.Column(3)
Me.lbLast = formFORM.listAppts.Column(4)
Me.tbDetails = formFORM.listAppts.Column(5)
End Sub
显然,Userform变量不会飞。救命? THX
答案 0 :(得分:0)
像正常一样调用表单,然后你可以循环浏览已经加载的表单,并在找到正确的表单后使用该变量。
Dim Obj As Object
For Each Obj In VBA.UserForms
'Assuming you only have one form open prior to showing this one
If StrComp(Obj.Name, Me.Name, vbTextCompare) = 0 Then
Me.lbSerial = Format(Obj.listAppts.Column(0), "0000")
Me.lbPSerial = Format(Obj.listAppts.Column(1), "0000")
Me.tbApptDate = Format(Obj.listAppts.Column(2), "MM/DD/YYYY")
Me.lbFirst = Obj.listAppts.Column(3)
Me.lbLast = Obj.listAppts.Column(4)
Me.tbDetails = Obj.listAppts.Column(5)
End If
Next Obj