2013-08-29 167 views
3

我不斷收到編譯消息「結尾沒有與」編譯錯誤與未與

即時通訊新爲此,我不能看到一個問題,我有一個「與」之後和「以結束」。如果我刪除結束與我得到一個如果與結束如果。

Private Sub Submitnewcustomer_Click() 
Dim RowCount As Long 
Dim ctl As Control 

If Me.companynameinput.Value = "" Then 
    MsgBox "Please enter a Company Name.", vbExclamation, "Britannia Monitoring Systems" 
    Me.companynameinput.SetFocus 
    Exit Sub 
End If 
If Me.contactnameinput.Value = "" Then 
    MsgBox "Please enter a Contact Name.", vbExclamation, "Britannia Monitoring Systems" 
    Me.companynameinput.SetFocus 
    Exit Sub 
End If 
If Me.addressinput.Value = "" Then 
    MsgBox "Please enter an Address.", vbExclamation, "Britannia Monitoring Systems" 
    Me.companynameinput.SetFocus 
    Exit Sub 
End If 
If Me.Telphone1input.Value = "" Then 
    MsgBox "Please enter at least 1 phone Number.", vbExclamation, "Britannia Monitoring Systems" 
    Me.Telphone1input.SetFocus 
    Exit Sub 
End If 
If Me.email1input.Value = "" Then 
    MsgBox "Please enter at least 1 Email Address.", vbExclamation, "Britannia Monitoring Systems" 
    Me.email1input.SetFocus 
End If 

RowCount = Worksheets("Database").Range("A1").CurrentRegion.Rows.Count 

    With Worksheets("Database").Range("A1") 
    .Offset(RowCount, 0).Value = Me.companynameinput.Value 
    .Offset(RowCount, 1).Value = Me.contactnameinput.Value 
    .Offset(RowCount, 2).Value = Me.Telphone1input.Value 
    .Offset(RowCount, 3).Value = Me.telephone2input.Value 
    .Offset(RowCount, 4).Value = Me.email1input.Value 
    .Offset(RowCount, 5).Value = Me.email2input.Value 
    .Offset(RowCount, 6).Value = Me.email3input.Value 
    .Offset(RowCount, 7).Value = Me.email4input.Value 
    .Offset(RowCount, 8).Value = Me.addressinput.Value 
    .Offset(RowCount, 15).Value = Format(Now, "dd/mm/yyyy hh:nn:ss") 
    If Me.CheckBox1.Value = True Then 
     .Offset(RowCount, 12).Value = "Yes" 
    Else 
     .Offset(RowCount, 12).Value = "No" 
    If Me.CheckBox2.Value = True Then 
     .Offset(RowCount, 13).Value = "Yes" 
    Else 
     .Offset(RowCount, 13).Value = "No" 
    If Me.CheckBox3.Value = True Then 
     .Offset(RowCount, 14).Value = "Yes" 
    Else 
     .Offset(RowCount, 14).Value = "No" 
    End If 
End With 

    For Each ctl In Me.Controls 
If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then 
    ctl.Value = "" 
ElseIf TypeName(ctl) = "CheckBox" Then 
    ctl.Value = False 
End If 
    Next ctl 
    End Sub 

我剛纔掙扎30分鐘,剛剛張貼這在這裏

任何幫助將是巨大的感謝

+0

我強烈建議使用http://www.oaltd.co.uk/Indenter/中的加載項,它可以自動縮進代碼,使得這些未關閉的循環/ ifs更容易找到。 – dendarii

回答

2

你缺少一對夫婦結束的IFS在本節。您需要在代碼正確編譯之前對其進行排序。

If Me.CheckBox1.Value = True Then 
    .Offset(RowCount, 12).Value = "Yes" 
Else 
    .Offset(RowCount, 12).Value = "No" 
If Me.CheckBox2.Value = True Then 
    .Offset(RowCount, 13).Value = "Yes" 
Else 
    .Offset(RowCount, 13).Value = "No" 
If Me.CheckBox3.Value = True Then 
    .Offset(RowCount, 14).Value = "Yes" 
Else 
    .Offset(RowCount, 14).Value = "No" 
End If 
+0

+1秒打了30秒 – 2013-08-29 16:00:59

+0

你知道爲什麼VBA不會在'With'語句中混合缺少'End If's嗎? – Holene