Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic forms 1

Status
Not open for further replies.

Bri123456

Programmer
Jan 3, 2002
30
CA
Hi I'm trying to create a form from a table in code. the table will be changing every few months and i want to create a control for this filed on the form. any ideas
 
Here's a start:

Public Sub DynamicForm()
Dim frm As Form
Dim ctlLabel As Control, ctlText As Control
Dim intDataX As Integer, intDataY As Integer
Dim intLabelX As Integer, intLabelY As Integer

' Create new form and set its record source.
Set frm = CreateForm
frm.RecordSource = "Table2"

' Set positioning values for new controls.
intLabelX = 100
intLabelY = 100
intDataX = 1000
intDataY = 100

Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("Table1")
Dim fld As Field
For Each fld In rs.Fields
' Create unbound default-size text box in detail section.
Set ctlText = CreateControl(frm.Name, acTextBox, , "", fld.Name, intDataX, intDataY)
' Create child label control for text box.
Set ctlLabel = CreateControl(frm.Name, acLabel, , ctlText.Name, fld.Name, intLabelX, intLabelY)
intLabelY = intLabelY + 300
intDataY = intDataY + 300
Next

' Restore form.
DoCmd.Restore
End Sub
 
FirstAndGoal4,


And a GOOD start. A bit more checking on the data type to set the control type might be nice. Placing the table name as an (input) argument would help generalize the process. But -as already and redundantly noted- a really good 'start'.

MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Thanks guys this has gioven me a great start, I appreciate your quick responses
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top