0

我有一个带有组合框的用户表单,该组合框填充了存储在隐藏表中的客户端名称列表。我正在尝试这样做,以便用户可以选择一个名称并单击一个按钮,该按钮会显示该客户的个人资料(姓名地址、电话号码等)。

在我做其他领域之前,我试图让它只为这个名字工作。当我查看个人资料时,名称标签(我命名为name_)是空白的。 ClientBox是名称为 on 的组合框的名称userform2,并且ClientProfile是具有 name_ 标签的用户窗体的名称。

注释掉的最后两行是我在尝试此方法之前尝试过的。两种方法都不起作用。

Sub ProfilePopulator()
    Dim index As Integer, str As String
    Application.ScreenUpdating = False
    Sheets("Clients").Visible = True
    Sheets("Clients").Select
    Range("A1").Select
    index = UserForm2.ClientBox.ListIndex
    str = Cells(index + 1, 1)
    ClientProfile.Name_.Caption = str
    'ActiveCell.Offset(index, 0).Select
    'ClientProfile.Name_.Caption = ActiveCell
End Sub
4

1 回答 1

0

问题实际上不在这部分代码中(哎呀)。它位于打开 ClientProfile 用户表单的按钮的代码中。在我有之前:

Private Sub CommandButton2_Click()
UserForm2.Hide
ClientProfile.Show
Call ProfilePopulator
End Sub

ProfilePopulator 必须在 ClientProfile 显示之前运行,所以现在它看起来像这样并且它可以工作:

Private Sub CommandButton2_Click()
UserForm2.Hide
Call ProfilePopulator
ClientProfile.Show
End Sub
于 2013-11-15T05:01:42.147 回答