[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 538
  • Last Modified:

place BuiltIn control on commandbar with VB

Hello experts,

In Access 2000 when I do customize a commandbar thrue the menu I can click on the 'commands' tab next I can place a form on my commandbar by drag and drop.

When I check in VB the type and Id and parameter I get the following results:
Type = 1,  Id=1837, Parameter="myFormName"

Then I try the following code:

commandbars("Mybar").controls.Add type:=1, id:=1837, parameter:="myFormName"

I get a runtime error: automation error

When I place a not builtIn-control then it works OK, but as soon I use id:= it does'nt work.

What I'am doing wrong

greetings DataMaat
0
DataMaat
Asked:
DataMaat
1 Solution
 
mbizupCommented:
Most of the built- in  controls work like that.  Unfortunately, 1837 for opening a specific form and it's report counterpart (1838, I believe do not work that way).

A good workaround is to make a "template" commandbar with any form on it, like you did initially.  Call this commandbar "MyTemplate"  Set the caption property of the openform button on your template commandbar to "Openform".  

You can then use VBA to copy the "openform" button to MyBar, and set its properties so that it opens whatever form you need:

Function CreateFormButton()
   dim obj as office.commandbarbutton
   
  'Copy the openform button to MyBar
   obj = Commandbars("MyTemplate").controls("OpenForm").copy Commandbars("MyBar")
  'Set its properties for the form you want to open
   obj.parameter = "Form1"
   obj.caption = "form1"

  'Copy the openform button to MyBar
   obj = Commandbars("MyTemplate").controls("OpenForm").copy Commandbars("MyBar")
  'Set its properties for the form you Want to open
   obj.parameter = "Form2"
   obj.caption = "form2"

'etc...

end function

0
 
DataMaatAuthor Commented:
Thanks a lot,

I've rewrite my code and it works fine for me.

But it is still strange you can't use the buitlin id's when you want add a builtin control

greetings from Holland.

DataMaat
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now