Is there a way to add a new control to a form during run time? I know you can do that in VB using the add method of a collection object, but I can not find a similar method in VBA?
Hi, <br> I don't know if you can add a control during run time, but if you create a control during design time and set it to ctl.Visible = False, then set it back to Visible = True during run time it will work the same way. Take note of the Name of the control<br><br><br>i.e <br>Private Sub Some_On_Click()<br><br>ctlName.Visible = True<br><br>End Sub<br><br>Cheers Radman
Thanks a lot for the quick response. The idea is to create the control only when there is a need to. For example I have a form that has a map of cities. The End user can click on any number of cities. Only those cities that has some entered values will be displayed on the map using lables. <br><br>Because the average end user usually enters data of a max of 10 cities, it make sense to only enter the records of selected cities and create labels on the fly on the form to show the values. In VB you can do that as well as in VFP and other languages. I was wondering about VBA?
Well then, <br><br>To create a control source in run i haven't done it, but if you look in the help files you will find it there.<br><br>if you are running Access '97 <br><br>Go the index -> controls, creating then select the<br> (CreateControl, CreateReportControl Functions) out of the dialog box<br><br><br>thats where it explains how to do it.<br><br>If you can't find that example here is the syntax and example for the files.<br><br>Syntax<br><br>CreateControl(formname, controltype[, section[, parent[, columnname[, left[, top[, width[, height]]]]]]])<br>CreateReportControl(reportname, controltype[, section[, parent[, columnname[, left[, top[, width[, height]]]]]]])<br><br><br><br>The following example first creates a new form based on an Orders table. It then uses the CreateControl function to create a text box control and an attached label control on the form.<br><br>Sub NewControls()<br> Dim frm As Form<br> Dim ctlLabel As Control, ctlText As Control<br> Dim intDataX As Integer, intDataY As Integer<br> Dim intLabelX As Integer, intLabelY As Integer<br><br> ' Create new form with Orders table as its record source.<br> Set frm = CreateForm<br> frm.RecordSource = "Orders"<br> ' Set positioning values for new controls.<br> intLabelX = 100<br> intLabelY = 100<br> intDataX = 1000<br> intDataY = 100<br> ' Create unbound default-size text box in detail section.<br><br>Set ctlText = CreateControl(frm.Name, acTextBox, , "", "", _<br> intDataX, intDataY)<br> ' Create child label control for text box.<br> Set ctlLabel = CreateControl(frm.Name, acLabel, , ctlText.Name, _<br> "NewLabel", intLabelX, intLabelY)<br> ' Restore form.<br> DoCmd.Restore<br>End Sub<br><br><br>Cheers Radman
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.