mercredi 13 décembre 2017

VBA Compile error: else without if

I'm getting the

Compile error: else without if

error on the first ElseIf in the following code block. As far as I'm aware the structure is correct, I have tried removing the white space and indentation with no luck. What am I missing?

Dim notesSQL As QueryDef
Dim Row As Integer
Dim Column, targetCell As String
Set notesSQL = db.QueryDefs("Export_Table_Notes_Filter")
Set rs = notesSQL.OpenRecordset()

If Insp_Template_No.Value = "Hazardous Area Equipment Detailed Inspection (Ex 'I' Ex 'iD' Ex 'nL)" Then
    Column = "b"
    Row = 16

    Do Until rs.EOF
        targetCell = (Column & Row)
        With wsheet
        .Range(targetCell).CopyFromRecordset rs
        End With

        targetCell = (count + 1)
ElseIf Insp_Template_No.Value = "Hazardous Area Equipment Visual Inspection (Ex 'd' and Ex 'e')" Then
    Column = "c"
    Row = 15

    Do Until rs.EOF
        targetCell = (Column & Row)
        With wsheet
        .Range(targetCell).CopyFromRecordset rs
        End With

        targetCell = (count + 1)
ElseIf Insp_Template_No.Value = "Hazardous Area Equipment Close Inspection (Ex 'I' Ex 'iD' Ex 'nL)" Then
    Column = "b"
    Row = 15

    Do Until rs.EOF
        targetCell = (Column & Row)
        With wsheet
        .Range(targetCell).CopyFromRecordset rs
        End With

        targetCell = (count + 1)
Else
    MsgBox ("Unrecognised inspection template")
End If

Loop

Aucun commentaire:

Enregistrer un commentaire