2017-05-08 5 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 DataEntryUserForm_Initialize()

にご Private Sub UserForm_Initialize()コードを変更してみてください(ダブルそれはコードです/編集を表示するユーザーフォームにクリックしてください)

(そして私はあなたのuserformを追加したのかどうかはわかりません。もしUserFormを追加しようとしないなら - Visuaでl Basic Editor Insert UserFormボタンをクリックするか、Insert> UserFormに移動します)

+0

ユーザフォームコーディングが追加されました – pmgibs

+0

結果はどうなりますか?それでも動作しない場合は、Visual Basicウィンドウを開き、F8キーを1つずつ押して、エラーを示している行/強調表示してください。 – Mertinc

関連する問題