none
option explicit causes error for defaultcontrol property

    Frage

  • I put option explicit into my Access 2010/VBA modules after reading "If you omit Option Explicit from any module, IMHO, you deserve everything you get." in an online post.

    One of my procedures restores the back style of a rectangle named "toothBox" with the following line of code:
      toothBox.BackStyle = Me.DefaultControl(acRectangle)
    But after I added Option Explicit I get an Error 438: Object doesn't support this property or method. 

    I changed by line of code to:
      toothBox.BackStyle = 0And now it works fine.  Does anyone know how to fix this so I can use the defaultcontrol property?  I'm restoring many, many objects in my Access form to their default after changing them during data entry, and the defaultcontrol property is not only handy but it makes my code more readable and easier to maintain.

    Thanks,  J'han


    J'han

    Mittwoch, 5. Dezember 2012 16:22

Antworten

  • I put option explicit into my Access 2010/VBA modules after reading "If you omit Option Explicit from any module, IMHO, you deserve everything you get." in an online post.

    One of my procedures restores the back style of a rectangle named "toothBox" with the following line of code:
      toothBox.BackStyle = Me.DefaultControl(acRectangle)
    But after I added Option Explicit I get an Error 438: Object doesn't support this property or method. 

    You aren't specifying what property of the default rectangle control you want.  Try this:

        toothBox.BackStyle = Me.DefaultControl(acRectangle).BackStyle


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    • Als Antwort markiert J'han Mittwoch, 5. Dezember 2012 16:47
    Mittwoch, 5. Dezember 2012 16:36

Alle Antworten

  • I put option explicit into my Access 2010/VBA modules after reading "If you omit Option Explicit from any module, IMHO, you deserve everything you get." in an online post.

    One of my procedures restores the back style of a rectangle named "toothBox" with the following line of code:
      toothBox.BackStyle = Me.DefaultControl(acRectangle)
    But after I added Option Explicit I get an Error 438: Object doesn't support this property or method. 

    You aren't specifying what property of the default rectangle control you want.  Try this:

        toothBox.BackStyle = Me.DefaultControl(acRectangle).BackStyle


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    • Als Antwort markiert J'han Mittwoch, 5. Dezember 2012 16:47
    Mittwoch, 5. Dezember 2012 16:36
  • Problem solved based on your suggestion; thanks for your help! 

    J'han

    Mittwoch, 5. Dezember 2012 16:50