Auto Create button by VBA

vss

Registered User.
Local time
Today, 15:24
Joined
Nov 27, 2008
Messages
11
Hi all,

I'm new here! And I wanna create a form that can auto create one or more random position buttons (number of button can be entered by user)

I have searched in all threads and there's some post show the way to create button by CreateControl function but when I do it, It's could not work in OnLoad Form.

Please help and sorry about my terrible English. :D
 
So when you have managed to create the buttons what are you intending to do with them?
 
So when you have managed to create the buttons what are you intending to do with them?

Ah yes, I will do something more with its.

I'm going to open a project can do:
I have two tables: product_cats and products
- Count Product_cats --> every product_cat will be showed by a button,...
- When user click on a button (a product_cat) on left panel, right panel will show a list of buttons as a list of products.
- When user click on product button, form will show price of that product
...

And upper question that I wanna make a simple form for my project.
Thank for your help!
 
Not wishing to state the obvious, but what happens when

a) the number of product categories reaches a level that leaves you no room on the screen.

b) how are you going to decide the size of the button to fit in with the description

c) how are you going to define the placement on the screen

d) when the form is loaded how is it going to know that new button need creating

e) what happens if you change the description of the category, how will it affect your layout

f) how are you going to organise the button on the screen

These questions are just the first few that I thought about.

Also are you aware that the only way to add a button to a screen is in design mode. Therefore at some point you are going to have to program it to do so. And if the front end is an MDE this is not possible.

I would suggest you have a listbox containing the categories in the left pane which when clicked would show the associated products in the right pane. At least with this method you can eliminate the majority of the above questions, as the listbox has a scroll feature.

David
 
All of upper things is go to this point: How to arrange and organize all buttons on screen (?)
- I think I can do it by matrix calculation.
- Number of product is just from 3 to 6 for each category.
With listbox, I have already done, but it don't make the face of application bright and with commandbutton will make more easy to use. Think click click click and click,... it will more comfortable than waiting for drop down and click. That's my idea.

But with CommandButton is hard to do, so I will surely do with listbox.
Thank you very much.
 
If you must go down that route the only feasable solution, but the most problematic is to create a multitude of button and place them on the screen where you would like them to appear. Make them all invisible. Next on the form load open the product category table as a recordset and enumerate through it one by one and for each category tell it that CmdButtonnn (where nn is the button number) to be visible and the caption is the category name. Do this for all categories.

Then when the user clicks on a button the OnClick event reads what the caption of the button is and passes this to a function that contains filter condition on the products table based on the category chosen, ie the button caption name. You will have to make sure that the name of the category does not exceed the limits of the button caption.

David
 
Perhaps it would be better to use the Access database as the database for this and create a standalone application using VB6 or VB.Net. In both of these it is much easier to create controls at run time.

For both VB6 (VBA is a stripped down version of VB6, just in case you were unaware) and VB.Net to add a control to a form you would do:
With VB6 using a ADO recordset, a checkbox created in the form designer, the other variables are for positioning the checkbox, and frInstallApplications is a frame created in the designer:
Code:
For iDone = 1 To rsCsv.RecordCount
    
        iRowCount = iRowCount + 1
        iCkIndex = rsCsv.Fields("CkBox").Value
        Load Check(iCkIndex)
        
        With Check(iCkIndex)
            .Left = ickboxLeftTemp
            .Top = ickboxTopTemp
            .Width = ickboxWidthDefault
            .Height = ickboxHeightDefault
            .Caption = rsCsv.Fields("DISPLAYNAME").Value
            .Container = frInstallApplications
            .Visible = True
        End With
        rsCSV.MoveNext
Next
I can't seem to find my VB.Net code for this project. I had written it, but then downgraded it to VB6 due to the target machines lacking the .Net framework (yes those do exist still).
 

Users who are viewing this thread

Back
Top Bottom