473,386 Members | 2,114 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,386 software developers and data experts.

Create Button On Tab control with button other form

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

-----------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. Private Sub pos_Click()
  2. Dim FormName As String
  3. Dim tab_page As pages
  4. Dim frm As form
  5. Dim tab_control as Control
  6.  
  7. FormName = "pos"
  8. DoCmd.OpenForm FormName, acDesign
  9.  
  10. Dim newBt As Control
  11.  
  12. Set frm = Forms!pos
  13. Set tab_control = frm!pos_products
  14. Set tab_page = tab_control!pages(1)
  15.  
  16. Set newBt = CreateControl(frm.name, acCommandButton, Left:=100 + 3000, Top:=500)
  17.  
  18. End Sub
Mar 13 '20 #1
5 3373
twinnyfo
3,653 Expert Mod 2GB
mnaem02,

Welcome to Bytes!

I'm not certain this can be done in VBA, as adding controls to a Tab Control requires that the Tab Control be the active object--And I don't know of a way to "Select" an object through VBA, like one can "select" a cell or a range of cells in Excel.

Some others might know how to do this. Sorry I couldn't be more hepp!

Any ideas, folks?
Mar 13 '20 #2
GazMathias
228 Expert 128KB
I wouldn't mind understanding the use case of this scenario.

I implemented a solution years ago where forms had several hidden buttons on them that were set visible on load when dynamically loaded configuration data demanded it. Each button was configured to call a handler and pass in it's label. The handler loaded configuration data based on that label for the event from a table and in many cases used eval to run new code stored there. Sadly the ecosystem has shifted and I work in .Net / JS land now and such things are simpler.

Gaz
Mar 13 '20 #3
i am trying to make Point of sale system where each tab will be category for example drinks ,burger etc and each category there will be products. these button i will use as products.

i can create buttons on the form and link on the category but it wont be dynamic for example if new category is created than i have to make manual form and add buttons where as if on the tab if i can make buttons than i can handle easily by adding page.

only i am stuck to create a button with vba on tab control ... in internet i have searched but no answer
Mar 13 '20 #4
twinnyfo
3,653 Expert Mod 2GB
I would offer an alternative idea:

Create two tables to cover your sales items:

Expand|Select|Wrap|Line Numbers
  1. tblFoodCategories
  2. fcID          Autonumber, PK
  3. FoodCategory  Text - Drinks, Burgers, Pizza etc.
and
Expand|Select|Wrap|Line Numbers
  1. tblFoodItems
  2. fiID      Autonumber, PK
  3. fcID      FK to tblFoodCategories
  4. FoodItem  Text - Pepsi, Diet Pepsi, Burger, Double Burger, Bacon Triple Cheeseburger, etc.
On your Tab Control, have a page set for each Food Category.

Create a Subform that is a continuous form, based upon tblFoodItems. The only control on the Form is a Command Button, with its caption set to the Food Item:
Expand|Select|Wrap|Line Numbers
  1. Me.cmdFoodItem.Caption = Me.FoodItem
Then, insert this subform onto each of your Tab Control Pages, including a filter for each Food Category.

Then, all you have to do is add code to your Sub form that will add food items to your sales invoice (which is beyond the scope of this thread).

If you add additional food categories, all you have to do is add another Tab Control Page, insert the Food Items subform and filter by the new category.

Hope this hepps!
Mar 16 '20 #5
GazMathias
228 Expert 128KB
Hi,

Imagine if you will a grid of 40 or so unbound buttons on a form, all of which are initially hidden, and a database structured with two levels of category with products that are tied to the outer category in a loose way.

When the form loads it displays on the top row of buttons as many of the categories as it can. Additional Next and Back buttons would be used to move between pages of these categories. Initially 0 - 7 would be loaded, then 8 - 15, etc. The categories could have a view order int column to load the most common first.

When clicking a top level category button, all sub categories will be loaded into as many of the lower buttons as needed and in turn when clicking one of those sub categories all products would be loaded.

Workflow would be:
Meal Deals -> Burgers -> Half Pounder, Chips and Drink -> Child Form appears to edit notes for kitchen, set qty, etc -> Add to order. Back.

Child form calls basket function in module. Module calls public function in form to refresh itself to update order total, qty, etc.

This is similar in theory to the solution I implemented.

Another way would be a column of buttons down one side of the form with a listview on the right. You would use a similar tier loading mechanism to the above but the same buttons would be reused each time and the products to order loaded into the listview.

Workflow is similar execept you click an item in the listview to load the child form. The benefit of this version is you can stuff hidden data into the listview and push it to the child form saving a database call and alloows for richer UI design, too, like long descriptions and back office notes (out of stock, etc).

Each method decouples the UI design from the data, like a web page would, which in all honesty would be my preferred platform for this. Day by day you only need to add data to the database as new categories and products are added and the UI will cater for them.

Each method requires a state machine so the event handlers know which tier / page the form should be rendering.

The native Access 'switchboard' mechanism functions similarly to this, or it used to in older versions. I haven't used one in a long time but when I did I abused the heck out of it. If it still does maybe you could have it build one in a test DB and you can take a look at how it works under the hood and perhaps have a crack at modifying it.

But it won't be dynamic for example if new category is created than I have to make manual form and add buttons
Do you see how these methods remove this problem? The buttons are always there but hidden and repurposed on demand, and the adding and changing of products is done in the db.

This may seem complicated but I promise you, once it clicks you'll change the way you think about project design.

Gaz
Mar 16 '20 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: uv | last post by:
Hi! I'm having problems submitting a new record through the form. I'm working with the wizard and I've added a control button to my form for entering entering a new record but for some reason it...
5
by: RAJ | last post by:
hi plz tell me how to know "how window is going to close"... i have to right code for X button of forms... plz telll me thanks bye
2
by: Quentin Huo | last post by:
Hi: I have a user control and I want to dynamically create a Label control and TextBox control when the button "add more author name" is clicked. I did like this: 1. there is a...
4
by: WebNewsReader | last post by:
This one should be easy ;) How can I create a button control at runtime using one that is already created and adjust the properties ? Thanks in advance
5
by: gregarican | last post by:
There is a C# CTI app I'm working on using Visual Studio 2005 at revision level 8.0.50727-7600. I need a couple of Windows Form Button controls to emulate line buttons on a telephone. So I went to...
2
by: migrant_lad | last post by:
form to view in pivot table view is based on query. form default view is pivot table and will function when the form is opened directly. The problem is that when the form is opened from a control...
0
by: wagswvu | last post by:
I am writing a User Control in C# that dynamically generates some text boxes and two buttons. For all the html on the page I am overriding the render method, I also render my Button/Textbox controls...
5
by: wassimdaccache | last post by:
Dear expert; using access 2003 . I have a table name "tables" that contains "tableid" & "tabledesc" The idea is to design a form that contains for each record in "tables-->tableid" a...
10
by: tajuddin | last post by:
I wanted to have a Command Button on a form to save a record & then ask to open a new record. I am new to access. I have MDFID on a form with primary key. Thanks Seth, To be frank, I...
2
by: Amian | last post by:
So I'll explain to you everything that I'm doing and then let you know what I need help with b/c maybe I should be doing this a different way. I am trying to create a database for all patient...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.