Results 1 to 5 of 5
  1. #1
    Akchayan is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Aug 2022
    Posts
    102

    Error during compilation (If and ElseIf)

    Hello together
    I have created an If and ElseIf structure that should be called when a button is pressed, but I always get an error when compiling. Here I have the code:



    Code:
    If IsNull(Me!FilterDatumVon) And IsNull(Me!FilterDatumBis) Then            DoCmd.ApplyFilter , "[IDKunde] = [Forms]![foUmsatz]![cmbKunde]"
      
        ElseIf IsNotNull(Me!FilterDatumVon) And IsNotNull(Me!FilterDatumBis) And IsNull(Me!Kunde) Then
                DoCmd.ApplyFilter , "[Rechnungsdatum] between " & Format(FilterDatum1, "\#yyyy\-mm\-dd\#") & _
                " AND " & Format(FilterDatum2, "\#yyyy\-mm\-dd\#")
    
    
        ElseIf IsNotNull(Me!FilterDatumVon) And IsNotNull(Me!FilterDatumBis) And IsNotNull(Me!Kunde) Then
                DoCmd.ApplyFilter , "[IDKunde] = [Forms]![foUmsatz]![cmbKunde2] And [Rechnungsdatum] between " & Format(FilterDatum3, "\#yyyy\-mm\-dd\#") & _
                " AND " & Format(FilterDatum4, "\#yyyy\-mm\-dd\#")
                
        End If
    What is the reason for the error?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What's the error description? I'm not familiar with IsNotNull, which I suspect is invalid. Try

    ElseIf Not IsNull(Me!FilterDatumVon)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Oh, and if this is really all on one line, it can't be:

    If IsNull(Me!FilterDatumVon) And IsNull(Me!FilterDatumBis) Then DoCmd.ApplyFilter , "[IDKunde] = [Forms]![foUmsatz]![cmbKunde]"

    That would be mixing the one-line and block formats of If/Then and will throw a compile error. Drop the DoCmd... to the next line.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    Akchayan is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Aug 2022
    Posts
    102
    Quote Originally Posted by pbaldy View Post
    What's the error description? I'm not familiar with IsNotNull, which I suspect is invalid. Try

    ElseIf Not IsNull(Me!FilterDatumVon)
    Yes Thank you it worked

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Erreur de compilation
    By Djeli in forum Access
    Replies: 4
    Last Post: 05-26-2021, 02:18 AM
  2. Error on VBA code Compilation
    By Lou_Reed in forum Access
    Replies: 25
    Last Post: 09-01-2017, 02:47 PM
  3. Help with If...Then...ElseIf
    By willmafingerdo in forum Programming
    Replies: 2
    Last Post: 09-23-2016, 08:15 AM
  4. Replies: 1
    Last Post: 04-10-2015, 07:40 AM
  5. Form compilation failed?
    By pbuck in forum SharePoint
    Replies: 1
    Last Post: 11-26-2012, 02:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums