Solved How to create command button on tab control with vba in design mode on click from other form

mnaeem90

New member
Local time
Today, 23:04
Joined
Mar 14, 2020
Messages
7
I want to create button on tab control with VBA from different form. When i click to create button than with vba other form will open in a design view and create button on specific tab page.
example i have four tab pages page1 page2 page3 page4 now i want to create button on page 2

Private Sub pos_Click()
Dim FormName As String
Dim tab_page As pages
Dim frm As form
Dim tab_control as Control

FormName = "pos"
DoCmd.OpenForm FormName, acDesign

Dim newBt As Control

Set frm = Forms!pos
Set tab_control = frm!pos_products
Set tab_page = tab_control!pages(1)

Set newBt = CreateControl(frm.name, acCommandButton, Left:=100 + 3000, Top:=500)

End Sub
 
Last edited:
I am creating point of sale with different categories and each category have different products . category part i am covering with tab control pages it is done but i want to create products on each category..only one command button if i am able to create on specified control page than multiple with loop i can create multiple. with form i do not want to create.


I have searched on internet but not lucky to find any solution.
 
advise not to over do it when you can enter the category in tabular form. the category being a combobox.
 
I disagree that creating controls dynamically is hard, it is really easy. I do agree that it is a really bad idea for a lot of reasons. If you want to make it appear dynamic create the buttons ahead of time and show/hide as necessary. You can even "float" the button above the tab control (do not put it in a page) and make it appear as if it is on every tab. Then show, hide, change caption, change method for each tab change. It will appear to be assigned to a page.
 
I think It's a very bad Idear and I would think I may show a design floor somewhere

mick
 
category part done ,only want to create button on tab control with VBA on design mode, i want to know is it possible with VBA or not
 
i need one hint that is it possible with vba to create command button on tab control on pages...... than i will move..on
 
I searched for something similar to your question. I found this response that dealt with command button, page, and tab and I don't think it is helpful, but I'm passing it on for you to judge.
 
no this will work on the normal form view... not on design view as we can not add controls on normal view
 
Again this is a dumb idea for a lot of reasons. Not sure what part of dumb idea is confusing. There are much easier and much better ways to do this. It is a real good way to corrupt your db, but what do I know.

There are only two tricks.
1) You cannot call this code from the same form you plan to edit. Even if the code is in another module.
2) You need to set the Parent property by name. In the case of a tabctl it is a Page name.

I think Uncle Gizmo demonstrated all that is needed. I added a couple bells and whistles, but does not really add to the concept.
 

Attachments

i need one hint that is it possible with vba to create command button on tab control on pages...... than i will move..on

mnaeem90,
Yes, it is possible to do with one major limitation. You can NEVER compile the front end into a mde/accde for deployment if your code will need to open any form in the design view in production/live.

Something to keep in mind if you ever want to protect your forms after deployment.
 
Last edited:
thank you so much...i lost hope that it is possible in MS access and just saw reply mail today..

i want to know other than these forms where i can study VBA related to MS access

Above code is working till creation of button but VBA remain's open.
 
thank you so much...i lost hope that it is possible in MS access and just saw reply mail today..

i want to know other than these forms where i can study VBA related to MS access

Above code is working till creation of button but VBA remain's open.

found answer
Application.VBE.MainWindow.Visible = False
 

Users who are viewing this thread

Back
Top Bottom