Answer down below:
"Donna Sabol" <dsabol2000@yahoo.com> wrote in message
news:3fd778f5$0$196$75868355@news.frii.net...[color=blue]
> I've tried the code listed here by DFS, and I see the code that Rich
> just posted. Here is what I currently have (with my modifications):
>
> Private Sub Report_Open(Cancel As Integer)
>
> Dim db As Database
> Dim i As Integer
> Dim j As Integer
> Dim rs As Recordset
>
> Set db = CurrentDb()
>
> 'LINE UP CONTROLS
> For i = 1 To 12
> Me("txt" & i).Left = Me("lbl" & i).Left
> Me("txt" & i).Width = Me("lbl" & i).Width
> Me("sumTxt" & i).Left = Me("lbl" & i).Left
> Me("sumTxt" & i).Width = Me("lbl" & i).Width
> Next i
>
>
> 'SINCE THE CROSS-TAB RESULTS AREN'T KNOWN UNTIL THE QUERY IS RUN
> 'BIND THE CONTROLS AND SET LABELS AT RUN TIME
>
> 'FIRST BLANK OUT ALL LABELS AND TOTALS
> For i = 1 To 12
> Me("lbl" & i).Caption = ""
> Me("sumTxt" & i).Visible = False
> Next i
>
> 'BIND CONTROLS
> j = 1
> Set rs = db.OpenRecordset("USAGE_HISTORY_Crosstab")
> If j <= 12 Then 'MAX OF 12 TEXT BOXES
> For i = 3 To rs.Fields.Count - 1 '3 IS THE FIRST DATA FIELD
> Me("lbl" & (j)).Caption = rs(i).Name
> Me("txt" & (j)).ControlSource = rs(i).Name
> Me("sumTxt" & j).Visible = True
> j = j + 1
> Next i
> End If
> rs.Close
>
> End Sub
>
>
> My system doesn't seem to like the "Caption" statement though. I get
> "Object doesn't support this property or method". So I REM'd out the
> lines that blank out the controls and it did the same on the line that
> says "...Caption = rs(i)...". Is there another function I can use other
> than Caption?[/color]
Donna,
That code I gave you integrated with my own report, of course, which had
labels named "lbl1", "lbl2", etc. If you don't have labels with those
names, it won't work. Comment those lines out as well. But remember, you
need to not only bind the text boxes to the fields returned in the crosstab
query, but also set the corresponding label captions as well.
And looking at the code, which I edited a little before I posted it, I see
something illogical. Switch the initial If and For statements around. New
version:
j = 1
Set rs = db.OpenRecordset("USAGE_HISTORY_Crosstab")
For i = 3 To rs.Fields.Count - 1 '3 IS THE FIRST DATA FIELD
If j <= 12 Then 'MAX OF 12 TEXT BOXES
Me("lbl" & (j)).Caption = rs(i).Name
Me("txt" & (j)).ControlSource = rs(i).Name
Me("sumTxt" & j).Visible = True
j = j + 1
End If
Next i
rs.Close
[color=blue]
> Thanks for your help. I'm using Access 97 on a W2k machine.
>
>
> *** Sent via Developersdex
http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it![/color]