2017-05-08 38 views
1

我試圖讓ActiveX命令按鈕顯示名爲「DataEntryUserForm」的用戶窗體。用於顯示用戶表單的命令按鈕

Private Sub CommandButton1_Click() 

DataEntryUserForm.Show 

End Sub 

以上是命令按鈕的當前代碼。當我點擊按鈕我收到以下錯誤:

Run-time error '424'
Object required

我試圖四處尋找類似的問題,但找不到任何東西。

添加用戶表單代碼:(雙擊到您的用戶窗體查看/編輯它的代碼)

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 

回答

1

試着改變你的 Private Sub UserForm_Initialize()代碼

Private Sub DataEntryUserForm_Initialize()

(而且我不確定你是否添加了你的用戶窗體,如果沒有添加用戶窗體 - 在Visua中l基本編輯器單擊插入用戶窗體按鈕 - 或者去插入>用戶窗體)

+0

添加用戶表單編碼 – pmgibs

+0

那麼結果是什麼?如果它仍然不起作用,請嘗試打開Visual Basic窗口並逐個按F8,然後告訴我哪一行出現錯誤/突出顯示。 – Mertinc

相關問題