Commandbars Controls Collection

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve

    #1

    Commandbars Controls Collection

    I have Access97, 2000 and XP installed. I'm developing an Access97 project
    for a client. I have the following code in the Open event of a form:
    Dim Cbr As Object
    Dim Ctl As Object
    On Error GoTo ErrorHandler
    Set Cbr = CommandBars("Co urseCalendarMen u")
    Set Ctl = Cbr.Controls("F acility")
    Ctl.ListIndex = 1
    Set Ctl = Cbr.Controls("M onth")
    Ctl.ListIndex = Month(Date)
    Set Ctl = Cbr.Controls("Y ear")
    Ctl.ListIndex = Year(Date) - 2000
    I dim Cbr and Ctl as objects because the only reference I have is to the
    Microsoft Office 10.0 Library; Microsoft Office 8.0 Library is not in my
    list of references. The above code always runs without problem.

    I have the following code in a public function in the same form:
    Dim Cbr As Object
    Dim Ctl As Object
    Set Cbr = CommandBars("Co urseCalendarMen u")
    Set Ctl = Cbr.Controls("M onth")
    If Ctl.ListIndex > 1 Then
    Ctl.ListIndex = Ctl.ListIndex - 1
    Me!CalMonthNum = Ctl.ListIndex
    Call SetDate("M", -1)
    End If
    There are five other similar public functions. The six public functions will
    run for a while and then all of a sudden in all six functions I get a Error
    #13 Type Mismatch. The error occurs in the same place in all six functions -
    Set Ctl = Cbr.Controls(". ...."). Also if I do a compact, I immediately get
    this error when I try to run any of the six functions although the code in
    the Open event runs without a problem. What gets me is that the code line
    Set Ctl = Cbr.Controls(". ....") is in the Open event code and always runs
    without a problem while the same code line in the six functions throws up
    the error. Does anyone have any thoughts.

    Thanks,

    Steve



  • MGFoster

    #2
    Re: Commandbars Controls Collection

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Since the variable Ctl is a Control why don't you Dim it as a Control?
    If the control "Month" is a ComboBox, Dim it as a ComboBox. Since you
    say you have the Office 10.0 Library References checked, you can also
    Dim the variable Cbr as a CommandBar. If you can't then something is
    wrong w/ the db.

    --
    MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
    Oakland, CA (USA)

    -----BEGIN PGP SIGNATURE-----
    Version: PGP for Personal Privacy 5.0
    Charset: noconv

    iQA/AwUBQgvVnIechKq OuFEgEQI15ACfSq 76lFDDEdppxylWe cXcH1lK6+MAn1i1
    LeeRPB2FRFZo3SP yVz4g0bep
    =bfFy
    -----END PGP SIGNATURE-----


    Steve wrote:[color=blue]
    > I have Access97, 2000 and XP installed. I'm developing an Access97 project
    > for a client. I have the following code in the Open event of a form:
    > Dim Cbr As Object
    > Dim Ctl As Object
    > On Error GoTo ErrorHandler
    > Set Cbr = CommandBars("Co urseCalendarMen u")
    > Set Ctl = Cbr.Controls("F acility")
    > Ctl.ListIndex = 1
    > Set Ctl = Cbr.Controls("M onth")
    > Ctl.ListIndex = Month(Date)
    > Set Ctl = Cbr.Controls("Y ear")
    > Ctl.ListIndex = Year(Date) - 2000
    > I dim Cbr and Ctl as objects because the only reference I have is to the
    > Microsoft Office 10.0 Library; Microsoft Office 8.0 Library is not in my
    > list of references. The above code always runs without problem.
    >
    > I have the following code in a public function in the same form:
    > Dim Cbr As Object
    > Dim Ctl As Object
    > Set Cbr = CommandBars("Co urseCalendarMen u")
    > Set Ctl = Cbr.Controls("M onth")
    > If Ctl.ListIndex > 1 Then
    > Ctl.ListIndex = Ctl.ListIndex - 1
    > Me!CalMonthNum = Ctl.ListIndex
    > Call SetDate("M", -1)
    > End If
    > There are five other similar public functions. The six public functions will
    > run for a while and then all of a sudden in all six functions I get a Error
    > #13 Type Mismatch. The error occurs in the same place in all six functions -
    > Set Ctl = Cbr.Controls(". ...."). Also if I do a compact, I immediately get
    > this error when I try to run any of the six functions although the code in
    > the Open event runs without a problem. What gets me is that the code line
    > Set Ctl = Cbr.Controls(". ....") is in the Open event code and always runs
    > without a problem while the same code line in the six functions throws up
    > the error. Does anyone have any thoughts.[/color]

    Comment

    • Tom van Stiphout

      #3
      Re: Commandbars Controls Collection

      On Thu, 10 Feb 2005 07:40:07 GMT, "Steve" <nospam@nospam. spam> wrote:

      I don't use CommandBars much, so no specifics here.
      I too have many versions of Access on the same machine, and they are
      not always behaving as well as I would want them to. Sometimes the
      setup program wakes up when I launch one of them, presumably to fix up
      registry settings.
      I agree with MGFoster that you can use more strongly typed variables.
      I would certainly do so. Personally I only use As Object for late
      binding, which you are not doing here.
      Perhaps your project is corrupt. Export as text and re-import. Google
      Groups has info on SaveAsText and LoadFromText.

      -Tom.

      [color=blue]
      >I have Access97, 2000 and XP installed. I'm developing an Access97 project
      >for a client. I have the following code in the Open event of a form:
      >Dim Cbr As Object
      >Dim Ctl As Object
      >On Error GoTo ErrorHandler
      >Set Cbr = CommandBars("Co urseCalendarMen u")
      >Set Ctl = Cbr.Controls("F acility")
      >Ctl.ListInde x = 1
      >Set Ctl = Cbr.Controls("M onth")
      >Ctl.ListInde x = Month(Date)
      >Set Ctl = Cbr.Controls("Y ear")
      >Ctl.ListInde x = Year(Date) - 2000
      >I dim Cbr and Ctl as objects because the only reference I have is to the
      >Microsoft Office 10.0 Library; Microsoft Office 8.0 Library is not in my
      >list of references. The above code always runs without problem.
      >
      >I have the following code in a public function in the same form:
      >Dim Cbr As Object
      >Dim Ctl As Object
      >Set Cbr = CommandBars("Co urseCalendarMen u")
      >Set Ctl = Cbr.Controls("M onth")
      >If Ctl.ListIndex > 1 Then
      > Ctl.ListIndex = Ctl.ListIndex - 1
      > Me!CalMonthNum = Ctl.ListIndex
      > Call SetDate("M", -1)
      >End If
      >There are five other similar public functions. The six public functions will
      >run for a while and then all of a sudden in all six functions I get a Error
      >#13 Type Mismatch. The error occurs in the same place in all six functions -
      >Set Ctl = Cbr.Controls(". ...."). Also if I do a compact, I immediately get
      >this error when I try to run any of the six functions although the code in
      >the Open event runs without a problem. What gets me is that the code line
      >Set Ctl = Cbr.Controls(". ....") is in the Open event code and always runs
      >without a problem while the same code line in the six functions throws up
      >the error. Does anyone have any thoughts.
      >
      >Thanks,
      >
      >Steve
      >
      >[/color]

      Comment

      • Steve

        #4
        Re: Commandbars Controls Collection

        The question comes down to would a database with a reference to Microsoft
        Office 10
        library run on a machine with only Microsoft Office 8 library installed.

        Steve

        "MGFoster" <me@privacy.com > wrote in message
        news:wAQOd.5101 $UX3.2113@newsr ead3.news.pas.e arthlink.net...[color=blue]
        > -----BEGIN PGP SIGNED MESSAGE-----
        > Hash: SHA1
        >
        > Since the variable Ctl is a Control why don't you Dim it as a Control?
        > If the control "Month" is a ComboBox, Dim it as a ComboBox. Since you
        > say you have the Office 10.0 Library References checked, you can also
        > Dim the variable Cbr as a CommandBar. If you can't then something is
        > wrong w/ the db.
        >
        > --
        > MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
        > Oakland, CA (USA)
        >
        > -----BEGIN PGP SIGNATURE-----
        > Version: PGP for Personal Privacy 5.0
        > Charset: noconv
        >
        > iQA/AwUBQgvVnIechKq OuFEgEQI15ACfSq 76lFDDEdppxylWe cXcH1lK6+MAn1i1
        > LeeRPB2FRFZo3SP yVz4g0bep
        > =bfFy
        > -----END PGP SIGNATURE-----
        >
        >
        > Steve wrote:[color=green]
        > > I have Access97, 2000 and XP installed. I'm developing an Access97[/color][/color]
        project[color=blue][color=green]
        > > for a client. I have the following code in the Open event of a form:
        > > Dim Cbr As Object
        > > Dim Ctl As Object
        > > On Error GoTo ErrorHandler
        > > Set Cbr = CommandBars("Co urseCalendarMen u")
        > > Set Ctl = Cbr.Controls("F acility")
        > > Ctl.ListIndex = 1
        > > Set Ctl = Cbr.Controls("M onth")
        > > Ctl.ListIndex = Month(Date)
        > > Set Ctl = Cbr.Controls("Y ear")
        > > Ctl.ListIndex = Year(Date) - 2000
        > > I dim Cbr and Ctl as objects because the only reference I have is to the
        > > Microsoft Office 10.0 Library; Microsoft Office 8.0 Library is not in my
        > > list of references. The above code always runs without problem.
        > >
        > > I have the following code in a public function in the same form:
        > > Dim Cbr As Object
        > > Dim Ctl As Object
        > > Set Cbr = CommandBars("Co urseCalendarMen u")
        > > Set Ctl = Cbr.Controls("M onth")
        > > If Ctl.ListIndex > 1 Then
        > > Ctl.ListIndex = Ctl.ListIndex - 1
        > > Me!CalMonthNum = Ctl.ListIndex
        > > Call SetDate("M", -1)
        > > End If
        > > There are five other similar public functions. The six public functions[/color][/color]
        will[color=blue][color=green]
        > > run for a while and then all of a sudden in all six functions I get a[/color][/color]
        Error[color=blue][color=green]
        > > #13 Type Mismatch. The error occurs in the same place in all six[/color][/color]
        functions -[color=blue][color=green]
        > > Set Ctl = Cbr.Controls(". ...."). Also if I do a compact, I immediately[/color][/color]
        get[color=blue][color=green]
        > > this error when I try to run any of the six functions although the code[/color][/color]
        in[color=blue][color=green]
        > > the Open event runs without a problem. What gets me is that the code[/color][/color]
        line[color=blue][color=green]
        > > Set Ctl = Cbr.Controls(". ....") is in the Open event code and always[/color][/color]
        runs[color=blue][color=green]
        > > without a problem while the same code line in the six functions throws[/color][/color]
        up[color=blue][color=green]
        > > the error. Does anyone have any thoughts.[/color][/color]


        Comment

        • Tim Marshall

          #5
          Re: Commandbars Controls Collection

          Steve wrote:
          [color=blue]
          > Dim Cbr As Object[/color]
          [color=blue]
          > Set Cbr = CommandBars("Co urseCalendarMen u")[/color]
          [color=blue]
          > Dim Cbr As Object
          > Dim Ctl As Object
          > Set Cbr = CommandBars("Co urseCalendarMen u")
          > Set Ctl = Cbr.Controls("M onth")
          > If Ctl.ListIndex > 1 Then
          > Ctl.ListIndex = Ctl.ListIndex - 1
          > Me!CalMonthNum = Ctl.ListIndex
          > Call SetDate("M", -1)
          > End If
          > There are five other similar public functions. The six public functions will
          > run for a while and then all of a sudden in all six functions I get a Error
          > #13 Type Mismatch. The error occurs in the same place in all six functions -
          > Set Ctl = Cbr.Controls(". ...."). A[/color]


          I often manipulate my menus in my apps. However, I never bother setting
          a menu as an object or even use the commandbars collection. I tried
          years go, when I was exclusively in A97, but had too much trouble with it.

          When manipulating menus I never dim a variable for a menu/toolbar/short
          cut menu and use the ordinal number for the menu control (mainly because
          I may want to change menu, submenu control captions, ie, the month menu
          item might be:

          Commandbars("Co urseCalendarMen u").controls (2)

          Instead of trying to use the properties to get at items in a sub menu as
          you've done, I'll do this:

          Commandbars("Co urseCalendarMen u").controls(2) .controls(3).ca ption =
          "Whatever"

          I use enabled, state is a good one (for check marks, etc) and the
          visible properties.

          I have many, many apps in A97 that do this and I've never had a problem
          you've described (although it sounds vaguely familiar to me, perhaps
          from my attempts years ago to use the cb collection).

          Apps that have been converted to A2003 also seem to have no problems
          with this, either.
          --
          Tim http://www.ucs.mun.ca/~tmarshal/
          ^o<
          /#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
          /^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me

          Comment

          • Albert D. Kallal

            #6
            Re: Commandbars Controls Collection

            "Tim Marshall" <TIMMY!@PurpleP andaChasers.Moe rtherium> wrote in message
            news:cuijjq$3g8 $1@coranto.ucs. mun.ca...
            [color=blue]
            > When manipulating menus I never dim a variable for a menu/toolbar/short
            > cut menu and use the ordinal number for the menu control (mainly because I
            > may want to change menu, submenu control captions, ie, the month menu item
            > might be:
            >
            > Commandbars("Co urseCalendarMen u").controls (2)[/color]

            An excellent solution, and one that I used for years also. And, for the same
            reasons as Tim, I just found it works..and that was long before I ever
            thought I would be using ms-access 4 versions later!!!

            I found that not having to bother with the references in a97 was a big
            bonus, and I did not want to play with, or worry about refs. It seems many
            of us (well at least Tim and I think along the same lines, and eliminates
            any kinds of dependences is the trick here).

            I was under the impression that when you covert the a97 to XP, then *some*
            of the main would change correctly in this case. However, I always avoided
            any refs beyond the defaults (try creating a blank mdb in a97, and see the
            refs...that is ALL you should have).


            --
            Albert D. Kallal (Access MVP)
            Edmonton, Alberta Canada
            pleaseNOOSpamKa llal@msn.com



            Comment

            Working...