Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Dynamic Picture box, button...

Posted on 2000-05-03
3
Medium Priority
?
188 Views
Last Modified: 2010-05-02
Hi Experts,

  Can I check with you whether I can display picture boxes, buttons, label dynamically, that means I display them according to the number of records in my database.
is it possible ?
if yes, can show me some simple code on how to ?

Thanks
0
Comment
Question by:seahpc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 300 total points
ID: 2772967
The simplest method of this is to add one of each control to your form, set the index property to 0, (zero, not blank). You can then load additional elements of the control array using the load statement.

Here is an example:

rstData.MoveFirst
For intCount = 1 To rstData.RecordCount - 1
  Load txtText(intCount)
  txtText(intCount).Left = 100
  txtText(intCount).Top = 100 + 200 * intCount
  txtText(intCount).Text = rstData!TextField
  txtText(intCount).Visible = True
  Load lblLabel(intCount)
  lblLabel(intCount).Left = 2500
  lblLabel(intCount).Top = 100 + 200 * intCount
  lblLabel(intCount).Caption = rstData!LabelField
  lblLabel(intCount).Visible = True
  rstData.MoveNext
Next

To Clear Down:

rstData.MoveFirst
For intCount = 1 To rstData.RecordCount - 1
  Unload txtText(intCount)
  Unload lblLabel(intCount)
  rstData.MoveNext
Next
0
 
LVL 9

Expert Comment

by:Dalin
ID: 2772993
Surely you can.
Using controlArray.

After you open your recordset (say you call it MyRS), check how many record you have. Then use Load to add more picturebox, label and buttons.
At design time, you put one of each in your form. say you call it MyPic, MyBut, and MyLab. set the Index property to 0.

add the code to create the array
With MyRS
If .EOF = False then
     .MoveLast
     .MoveFirst
     MyLab(0).Caption = !somefieldName
     MyBut(0).caption = !SomeFieldName
     MyPic(0).Picture = Whatever
     If .RecordCount > 1 then
             For i   = 1 to .RecordCount -1
                   .MoveNext
                   Load MyLab(i)
                   Load MyBut(i)
                   Load MyPic(i)
                    MyLab(i).Caption = !somefieldName
                     MyBut(i).caption = !SomeFieldName
                    MyPic(i).Picture = Whatever
                  'set the position in the form
                   MyLab(i).Left = whatever
                   MyLab(i).Top = whatever
                  ...
               Next i
         End If
End With






0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2774141
an alternative to creating a control array:

http://support.microsoft.com/support/kb/articles/Q190/6/70.ASP?LNG=CAN&SA=&FR=0

it also allows you to add controls that arent on your form to begin with

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question