Sad Der
accessd666 at yahoo.com
Fri Oct 31 06:57:49 CST 2003
Hi group,
I need to create a lot of forms. All with the same
layout.
Top of the page has a listbox (lstHeader) that shows
all fields/records from a table.
Bottom of the page has 11-54 textboxes (the number of
textboxes equals the number of columns in the textbox)
The labels are named: lbl1..through lbl54
The textboxes are named: txt1 through txt54
I want to:
1 - rename the labels to match the column name
2 - bind the rControlSource prop of the textbox to
link to the approp. listbox column e.g.:
txt1.controlsource = lstHeader.column(1)
Can anybody give me some tips on how to do steps 1 and
2? I've added my code below.
TIA
SD
Private Sub Form_Load()
Dim rst As ADODB.Recordset
Dim fld As ADODB.Field
Dim intFldCount As Integer
'-------------------------------------------
Dim intI As Integer
Dim frm As Form
Dim intfrmCount As Integer
Dim astrCtlName() As String
Dim astrColName() As String
Dim i As Integer
Dim intCnt As Integer
'-------------------------------------------
'add rowsource to listbox
lstHeader.RowSource = "tblTest"
'Count columns
Set rst = New ADODB.Recordset
rst.Open "[tblTest]", CurrentProject.Connection
intFldCount = rst.Fields.Count
'Initialize the array to hold control names
ReDim astrColName(0 To intFldCount - 1)
'Store columnnames in Array
For intI = 0 To rst.Fields.Count - 1
Set fld = rst.Fields(intI)
astrColName(intI) = fld.Name
Next intI
'loop through columns
For i = 0 To intFldCount - 1
Debug.Print astrColName(i)
Next i
'Count form objects
Set frm = Forms("Form1XXXX")
intfrmCount = frm.Count
For i = 0 To intfrmCount - 1
Debug.Print frm(i).ControlType
Select Case frm(i).ControlType
Case acLabel
'rename the label
Debug.Print frm(i).Name
Case acTextBox
'link textbox to lstHeader.column(i)
Debug.Print frm(i).Name
Case Else
End Select
Next i
End Sub
__________________________________
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/