none
I cannot see why I am getting COMPILE error when i click on Debug. "Else Without IF" my count seems ok, No Do Loops. RRS feed

  • Question

  • Public Static Function funGetFont() As String             'function in a standard module.     Is Static because want to call many times and return the value in each record once.  so I think I need to make it Static

    'yes I know the code is not done at this point.

    'but I cannot figure out why I get the compile error when I click on Debug of  "Else Without IF"  Even deleted and reentered IF.

    If mReSet = True Then                               'mReSet is a module variable (Boolean)  so can set true in Report Open
        Dim dbs As DAO.Database
        Dim rst As DAO.Recordset
        Set dbs = CurrentDb
       
        Set rst = dbs.OpenRecordset("qFontsAllTblMyFonts")     'qry is to get all records in a table where field picked = true
        
        With rst
            .MoveFirst
            mReSet = False  'Because I do not want to create this record set more than once.
    Else                                   ' THIS  Else gets high lighted in the error.
        .MoveNext
              If .EOF Then
                   .MoveFirst
              End If
       
    End If
            End With

    End Function


    Mark J

    Sunday, August 21, 2016 10:27 AM

Answers

  • George,

    Thanks

    I put the End With    before the    Else

    and added    With rst after the Else   

    and just before   End IF and I NO LONGER get the error.

    I never ran into something like this before.  This is one I am keeping in my set of notes I keep close.

    I am a bit embarrassed to miss something like this in the documentation I have been able to find on this error. any idea of where I should have been looking for info on this. I am trying to learn. 

    if this is one of those answers that is just passed along and NOT posted at https://msdn.microsoft.com/en-us/library/office/gg264723.aspx   ?    your working answer was not on the link for "With" on 8/21/16 8 am

    Thanks again for the working info.

    Mark J


    Mark J

    • Marked as answer by PuzzledByWord Sunday, August 21, 2016 4:39 PM
    Sunday, August 21, 2016 2:59 PM

All replies

  • That is because you have the nesting wrong. You need to end the With with End With before the Else.
    As it is now, the Else "belongs" to With which will produce a compiler error.

    Best regards, George

    Sunday, August 21, 2016 10:35 AM
  • George,

    Thanks

    I put the End With    before the    Else

    and added    With rst after the Else   

    and just before   End IF and I NO LONGER get the error.

    I never ran into something like this before.  This is one I am keeping in my set of notes I keep close.

    I am a bit embarrassed to miss something like this in the documentation I have been able to find on this error. any idea of where I should have been looking for info on this. I am trying to learn. 

    if this is one of those answers that is just passed along and NOT posted at https://msdn.microsoft.com/en-us/library/office/gg264723.aspx   ?    your working answer was not on the link for "With" on 8/21/16 8 am

    Thanks again for the working info.

    Mark J


    Mark J

    • Marked as answer by PuzzledByWord Sunday, August 21, 2016 4:39 PM
    Sunday, August 21, 2016 2:59 PM
  • If this was the answer you were looking for, then please mark my reply as an answer for others to benefit from.

    Best regards, George

    Sunday, August 21, 2016 3:06 PM
  • George,

    I would have sworn I did mark as answer 1hr 40 minutes ago.  I see it is NOT showing as a answer so I just did.

    please look at the link I added.   it didn't mention any problems "with" and "Else".

    was I looking at the wrong spot for where your info about the "Nesting" problem?

    mark j


    Mark J

    Sunday, August 21, 2016 4:45 PM