Solved

Dynamic Picture box, button...

Posted on 2000-05-03
3
179 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
3 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 100 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now