i have a database with 3 tables,
table1 contains items price and date is linked to table2,primary key in form
table2 contains description of item and category
table3 contains date and used is linked to table1,primary key in form as dataview
union query day/week/month contains price per day/week/month in form1 linked to table1
query contains unused items in form2
crossquery contains used per week in form3
only form3 has problem because of growing number of weeks to display in top row
often i get error about ole but i not use ado nor dao just database but i added ado/dao/activex
if i put the dynamic code in form then i debug.print table1 but not controls (how print controls?)
if i put the dynamic code in form3 then i not see any table
the code :
Option Compare Database
Private Sub Form_Open(Cancel As Integer)
Me.Recordset.MoveLast ' ! for table1 rest for table3
Dim intColCount As Integer
Dim intControlCount As Integer
Dim i As Integer
Dim StrName As String
On Error Resume Next
intColCount = Me.Recordset.Fields.Count
intControlCount = Me.Detail.Controls.Count
Debug.Print "field:" & intColCount & "::" & intControlCount (result "field:4::10)
If intControlCount < intColCount Then
intColCount = intControlCount
End If
For i = 1 To intColCount
StrName = Me.Recordset.Fields(i - 1).Name
Me.Controls("lblPgHdr" & i).Caption = StrName
Me.Controls("tbxData" & i).ControlSource = StrName
Me.Controls("tbxSum" & i).ControlSource = _
"=Sum([" & StrName & "])"
Debug.Print "name:" & StrName (4lines : id week item price)
Next i
For i = intColCount + 1 To intControlCount
Me.Controls("tbxData" & i).Visible = False
Me.Controls("lblPgHdr" & i).Visible = False
Me.Controls("tbxSum" & i).Visible = False
Next i
End Sub
if i know where to put what event and how to print controls that will help a lot already