命令按钮代码停止工作

Command Button Code stopped working

我昨天使用了这个用户表单代码,一切正常。今天,什么都不起作用。单击我的命令按钮 "Complete" 时,代码应验证用户表单是否完整 (Complete_Enter()),然后将信息从用户表单传输到我的工作表。这一切在昨天和今天都完美无缺。相反,当我单击完成时,VBA 仅运行 Complete_Enter() 子项下的第一行。这是代码:

Private Sub ConnectorCoverProductionForm_Initialize()

'Empty Serial_NumberTextBox
Serial_Number.Value = ""
Serial_Number.SetFocus

'Empty Order_NumberTextBox
Order_Number.Value = ""

'Empty DateTextBox
TextBox1.Value = ""

Inspector.Clear
Assembler.Clear
Process_Code.Clear

'Uncheck OptionButton
OptionButton1.Value = False
OptionButton2.Value = False
OptionButton3.Value = False
OptionButton4.Value = False
OptionButton5.Value = False
OptionButton6.Value = False
OptionButton21.Value = False
OptionButton12.Value = False
OptionButton13.Value = False
OptionButton14.Value = False
OptionButton15.Value = False
OptionButton16.Value = False


End Sub
Private Sub Assembler_DropButtonClick()
Assembler.List = Array("Trung", "Jesus", "Khoi", "Josie", "Omi")
End Sub
Private Sub ClearALL_Click()

Call ConnectorCoverProductionForm_Initialize

End Sub

Private Sub CommandButton1_Click()
Shell ("Explorer \PC148\Assembly Group\Traveler 
End Sub
Private Sub CommandButton2_Click()
Shell ("Explorer \PC148\Assembly Group\Traveler               
End Sub

Private Sub CommandButton3_Click()
Shell ("Explorer \PC148\Assembly Group\Traveler Templates\Videos\Edited\Mag 
End Sub

Private Sub CommandButton4_Click()
Shell ("Explorer \PC148\Assembly Group\Traveler Templates\Videos\Edited\Mag 
End Sub

Private Sub Complete_Click()

Dim emptyRow As Long

Sheet1.Activate

emptyRow = WorksheetFunction.CountA(Range("C:C")) + 1

Cells(emptyRow, 3).Value = Serial_Number.Value
Cells(emptyRow, 4).Value = Order_Number.Value
Cells(emptyRow, 5).Value = TextBox1.Value
Cells(emptyRow, 6).Value = Revision.Value
Cells(emptyRow, 7).Value = Inspector.Value
Cells(emptyRow, 8).Value = Assembler.Value
Cells(emptyRow, 9).Value = Process_Code.Value
If OptionButton1.Value = True Then Cells(emptyRow, 10).Value =         OptionButton1.Caption
If OptionButton21.Value = True Then Cells(emptyRow, 10).Value = OptionButton21.Caption
If OptionButton2.Value = True Then Cells(emptyRow, 11).Value = OptionButton2.Caption
If OptionButton12.Value = True Then Cells(emptyRow, 11).Value = OptionButton12.Caption
If OptionButton3.Value = True Then Cells(emptyRow, 12).Value = OptionButton3.Caption
If OptionButton13.Value = True Then Cells(emptyRow, 12).Value = OptionButton13.Caption
If OptionButton4.Value = True Then Cells(emptyRow, 13).Value = OptionButton4.Caption
If OptionButton14.Value = True Then Cells(emptyRow, 13).Value = OptionButton14.Caption
If OptionButton5.Value = True Then Cells(emptyRow, 14).Value = OptionButton5.Caption
If OptionButton15.Value = True Then Cells(emptyRow, 14).Value = OptionButton15.Caption
If OptionButton6.Value = True Then Cells(emptyRow, 15).Value = OptionButton6.Caption
If OptionButton16.Value = True Then Cells(emptyRow, 15).Value = OptionButton16.Caption

End Sub

Private Sub Complete_Enter()

If Serial_Number.Value = "" Then MsgBox "Fill in Serial Number"
Exit Sub

If Order_Number.Value = "" Then MsgBox "Fill in Order Number"
Exit Sub

If TextBox1.Value = "" Then MsgBox "Fill in Date"
Exit Sub
If Revision.Value = "" Then MsgBox "Select the correct Revision"
Exit Sub
If Inspector.Value = "" Then MsgBox "Who was the inspector? If it was you,select 'SELF'"
Exit Sub
If Assembler.Value = "" Then MsgBox "Select Your Name as the Assembler"
Exit Sub
If Process_Code.Value = "" Then MsgBox "Select the correct Process Code"
Exit Sub
If OptionButton1.Value = False And OptionButton21.Value = False Then MsgBox "What is the Status of Step 1"
Exit Sub
If OptionButton2.Value = False And OptionButton12.Value = False Then MsgBox "What is the Status of Step 2"
Exit Sub
If OptionButton3.Value = False And OptionButton13.Value = False Then MsgBox "What is the Status of Step 3"
Exit Sub
If OptionButton4.Value = False And OptionButton14.Value = False Then MsgBox "What is the Status of Step 4"
Exit Sub
If OptionButton5.Value = False And OptionButton15.Value = False Then MsgBox "What is the Status of Step 5"
Exit Sub
If OptionButton6.Value = False And OptionButton16.Value = False Then MsgBox "What is the Status of Step 6"
Exit Sub


End Sub

Private Sub Inspector_DropButtonClick()
Inspector.List = Array("Tom", "Tre", "Omi", "Self")
End Sub

Private Sub Process_Code_DropButtonClick()
Process_Code.List = [index(12*(row(1:12)-1),)]
End Sub
Private Sub Revision_DropButtonClick()
Revision.List = [index(char(64+row(1:26)),)]
End Sub

我希望你的例程应该像这样修改:

Private Sub Complete_Enter()
    If Serial_Number.Value = "" Then
        MsgBox "Fill in Serial Number"
    ElseIf Order_Number.Value = "" Then
        MsgBox "Fill in Order Number"
    ElseIf TextBox1.Value = "" Then
        MsgBox "Fill in Date"
    ElseIf Revision.Value = "" Then
        MsgBox "Select the correct Revision"
    ElseIf Inspector.Value = "" Then
        MsgBox "Who was the inspector? If it was you,select 'SELF'"
    ElseIf Assembler.Value = "" Then
        MsgBox "Select Your Name as the Assembler"
    ElseIf Process_Code.Value = "" Then
        MsgBox "Select the correct Process Code"
    ElseIf OptionButton1.Value = False And OptionButton21.Value = False Then
        MsgBox "What is the Status of Step 1"
    ElseIf OptionButton2.Value = False And OptionButton12.Value = False Then
        MsgBox "What is the Status of Step 2"
    ElseIf OptionButton3.Value = False And OptionButton13.Value = False Then
        MsgBox "What is the Status of Step 3"
    ElseIf OptionButton4.Value = False And OptionButton14.Value = False Then
        MsgBox "What is the Status of Step 4"
    ElseIf OptionButton5.Value = False And OptionButton15.Value = False Then
        MsgBox "What is the Status of Step 5"
    ElseIf OptionButton6.Value = False And OptionButton16.Value = False Then
        MsgBox "What is the Status of Step 6"
    End If
End Sub