用于显示用户表单的命令button

我试图有一个ActiveX命令button显示名为“DataEntryUserForm”的用户表单。

Private Sub CommandButton1_Click() DataEntryUserForm.Show End Sub 

以上是命令button的当前代码。 当我点击button我收到以下错误:

运行时错误'424'
所需对象

我试图寻找类似的问题,但找不到任何东西。

添加用户表单代码:

 Private Sub DataEntryUserForm_Initialize() 'Empty PatientIdentifierTextBox PatientIdentifierTextBox.Value = "" 'Empty AgeTextBox AgeTextBox.Value = "" 'Empty SexComboBox SexComboBox.Clear 'Fill SexComboBox With SexComboBox .AddItem "Male" .AddItem "Female" End With 'Unselect AlergiesOptionButtons AllergiesYesOptionButton1.Value = False AllergiesNoOptionButton2.Value = False 'Set no car as default CarOptionButton2.Value = True 'Empty PrimaryDiagnosisTextBox PrimaryDiagnosisTextBox.Value = "" 'Empty ReasonforTransfusionTextBox ReasonforTransfusionTextBox.Value = "" 'Empty NumberofTransfusionsTextBox NumberofTransfusionsTextBox.Value = "" 'Empty TypeofTRXNComboBox TypeofTRXNComboBox.Clear 'Fill TypeofTRXNComboBox With TypeofTRXNComboBox .AddItem "TACO" .AddItem "TRALI" .AddItem "TAD" .AddItem "Allergic Reaction" .AddItem "Hypotensive TRXN" .AddItem "FNHTR" .AddItem "AHTR" .AddItem "DHTR" .AddItem "DSTR" .AddItem "TAGVHD" .AddItem "TTI" .AddItem "Other" End With 'Empty TreatmentofTRXNTextBox TreatmentofTRXNTextBox.Value = "" 'Empty NumberofTransfusionsBeforeTextBox NumberofTransfusionsBeforeTextBox.Value = "" 'Empty SignsSymptomsTextBox SignsSymptomsTextBox.Value = "" 'Empty ImputabilityComboBox1 ImputabilityComboBox1.Clear 'Fill ImputabilityComboBox1 With ImputabilityComboBox1 .AddItem "Definite" .AddItem "Probable" .AddItem "Possible" .AddItem "Doubtful" .AddItem "Ruled Out" .AddItem "Not Determined" End With 'Empty SeverityComboBox2 SeverityComboBox2.Clear 'Fill SeverityComboBox2 With SeverityComboBox2 .AddItem "Non-Severe" .AddItem "Severe" .AddItem "Life-threatening" .AddItem "Death" End With 'Unselect TreatmentOptionButtons TreatmentDrugOptionButton1.Value = False TreatmentProductsOptionButton2.Value = False TreatmentDrugandProductOptionButton3.Value = False 'Empty TypeofDrugTextBox TypeofDrugTextBox.Value = "" 'Clear ProductModCheckBox VolumeReductionCheckBox1.Value = False SalineWashingCheckBox2.Value = False 'Empty TRXNBeforeChangeTextBox TRXNBeforeChangeTextBox.Value = "" 'Empty TRXNAfterChangeTextBox TRXNAfterChangeTextBox.Value = "" 'Set Focus on NameTextBox NameTextBox.SetFocus End Sub Private Sub OKButton_Click() Dim emptyRow As Long 'Make Sheet1 active Sheet1.Activate 'Determine emptyRow emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1 'Transfer information Cells(emptyRow, 1).Value = PatientIdentifierTextBox.Value Cells(emptyRow, 2).Value = AgeTextBox.Value Cells(emptyRow, 3).Value = SexComboBox.Value Cells(emptyRow, 5).Value = PrimaryDiagnosisTextBox.Value Cells(emptyRow, 6).Value = ReasonforTransfusionTextBox.Value Cells(emptyRow, 7).Value = NumberofTransfusionsTextBox.Value Cells(emptyRow, 8).Value = TypeofTRXNComboBox.Value Cells(emptyRow, 9).Value = TreatmentofTRXNTextBox.Value Cells(emptyRow, 10).Value = NumberofTransfusionsBeforeTextBox.Value Cells(emptyRow, 11).Value = SignsSymptomsTextBox.Value Cells(emptyRow, 12).Value = ImputabilityComboBox1.Value Cells(emptyRow, 13).Value = SeverityComboBox2.Value Cells(emptyRow, 15).Value = TypeofDrugTextBox.Value Cells(emptyRow, 17).Value = TRXNBeforeChangeTextBox.Value Cells(emptyRow, 18).Value = TRXNAfterChangeTextBox.Value If AllergiesYesOptionButton1.Value = True Then Cells(emptyRow, 4).Value = AllergiesYesOptionButton1.Caption If AllergiesNoOptionButton2.Value = True Then Cells(emptyRow, 4).Value = Cells(emptyRow, 4).Value & " " & AllergiesNoOptionButton2.Caption End If If TreatmentDrugOptionButton1.Value = True Then Cells(emptyRow, 14).Value = TreatmentDrugOptionButton1.Caption If TreatmentProductsOptionButton2.Value = True Then Cells(emptyRow, 14).Value = Cells(emptyRow, 14).Value & " " & TreatmentProductsOptionButton2.Caption If TreatmentDrugandProductOptionButton3.Value = True Then Cells(emptyRow, 14).Value = Cells(emptyRow, 14).Value & " " & TreatmentDrugandProductOptionButton3.Caption End If If VolumeReductionCheckBox1.Value = True Then Cells(emptyRow, 16).Value = VolumeReductionCheckBox1.Caption If SalineWashingCheckBox2.Value = True Then Cells(emptyRow, 16).Value = Cells(emptyRow, 16).Value & " " & SalineWashingCheckBox2.Caption End If End Sub Private Sub ClearButton_Click() Call UserForm_Initialize End Sub Private Sub CancelButton_Click() Unload Me End Sub 

尝试改变你的Private Sub UserForm_Initialize ()代码

Private Sub DataEntryUserForm_Initialize ()

(双击进入您的用户表单查看/编辑它的代码。)

(而且我不确定是否添加了用户窗体,如果不尝试添加用户窗体 – 在Visual Basic编辑器中单击插入用户窗体button – 或者去插入>用户窗体)