473,387 Members | 3,787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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("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

Nov 13 '05 #1
5 4667
-----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/AwUBQgvVnIechKqOuFEgEQI15ACfSq76lFDDEdppxylWecXcH1 lK6+MAn1i1
LeeRPB2FRFZo3SPyVz4g0bep
=bfFy
-----END PGP SIGNATURE-----
Steve wrote:
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.

Nov 13 '05 #2
On Thu, 10 Feb 2005 07:40:07 GMT, "Steve" <no****@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.

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


Nov 13 '05 #3
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:wA*****************@newsread3.news.pas.earthl ink.net...
-----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/AwUBQgvVnIechKqOuFEgEQI15ACfSq76lFDDEdppxylWecXcH1 lK6+MAn1i1
LeeRPB2FRFZo3SPyVz4g0bep
=bfFy
-----END PGP SIGNATURE-----
Steve wrote:
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.

Nov 13 '05 #4
Steve wrote:
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).cont rols(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.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Nov 13 '05 #5
"Tim Marshall" <TI****@PurplePandaChasers.Moertherium> wrote in message
news:cu**********@coranto.ucs.mun.ca...
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).
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
http://www.members.shaw.ca/AlbertKallal
Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Nathan Bloomfield | last post by:
Hi there people, Is it possible to turn on/off functions in the "options screen" using the "CommandBars" reference? If it is possible, I cannot work out the syntax, but I assume it is...
1
by: deko | last post by:
I'm trying to prevent any built-in command bars or menu bars from appearing in an Access MDE. I have the following code on the Form_Open event of the app's main form: CommandBars("Menu...
16
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
4
by: Anushya | last post by:
Hi I am creating a outlook addins and in that OnConnection i am creating a toolbar(Commandbars). the code is working fine.. But the problem is when i access a custom form on the click of a...
66
by: Cor | last post by:
Hi, I start a new thread about a discussion from yesterday (or for some of us this morning). It was a not so nice discussion about dynamically removing controls from a panel or what ever. It...
0
by: SunSet | last post by:
Hello togehther, i want to add a new Popup to the Contextmenue in Word (Right click on the textbody) which all is included in an AddIn. To add a new button works fine with these piece of code: ...
15
by: Arpan | last post by:
Consider the following code which retrieves data from a SQL Server 2005 DB table & displays it in a DataGrid: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)...
0
by: robert.waters | last post by:
I recently 'messed with' the CommandBars on one of my apps, in the process of learning how to create custom menus and disable default ones. Unfortunately, now *every* Access database I open...
9
by: dhtml | last post by:
I have written an article "Unsafe Names for HTML Form Controls". <URL: http://jibbering.com/faq/names/ > I would appreciate any reviews, technical or otherwise. Garrett --...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.