Commandbars Controls Collection

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

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("CourseCalendarMenu")
Set Ctl = Cbr.Controls("Facility")
Ctl.ListIndex = 1
Set Ctl = Cbr.Controls("Month")
Ctl.ListIndex = Month(Date)
Set Ctl = Cbr.Controls("Year")
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("CourseCalendarMenu")
Set Ctl = Cbr.Controls("Month")
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
 
-----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:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

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

iQA/AwUBQgvVnIechKqOuFEgEQI15ACfSq76lFDDEdppxylWecXcH1lK6+MAn1i1
LeeRPB2FRFZo3SPyVz4g0bep
=bfFy
-----END PGP SIGNATURE-----
 
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
 
Steve said:
Dim Cbr As Object
Set Cbr = CommandBars("CourseCalendarMenu")
Dim Cbr As Object
Dim Ctl As Object
Set Cbr = CommandBars("CourseCalendarMenu")
Set Ctl = Cbr.Controls("Month")
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


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("CourseCalendarMenu").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("CourseCalendarMenu").controls(2).controls(3).caption =
"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.
 
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("CourseCalendarMenu").controls(2)

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).
 
Back
Top