G
Guest
I've posted a question on form coding, but it's probably the wrong group. At
this point, I'm trying to create a dynamic crosstab report using code I found
in "Fixing Access Annoyances" by Phil Mitchell and Evan Callahan. My first
four column are static, but the next 6 need to be dynamic (e.g., display 1 or
many). Following is the code which gets "stuck" in the following line -
Set rst = CurrentDb.OpenRecordset(Me.RecordSource).
Don't know if the rest would work, because I don't get very far. Can anyone
please help:
Option Compare Database
Option Explicit
Private Sub Report_Open(Cancel As Integer)
Dim rst As DAO.Recordset
Dim intFields As Integer
Dim intControls As Integer
Dim N As Integer
'Open a recordset for the crosstab query.
Set rst = CurrentDb.OpenRecordset(Me.RecordSource)
' Find the number of text boxes available in the Detail section, minus 4
because we don't count the first 4 row header controls.
intControls = Me.Detail.Controls.Count - 4
' Find the number of fields, minus 4, because we don't count the first 4 row
header filed.
intFields = rst.Fields.Count - 4
' We can't use more than intControls number of fields.
If intFields > intControls Then
intFields = intControls
End If
' Iterate through report fields to set label captions and field control
sources.
For N = 1 To intControls
If N <= intFields Then
Me.Controls("Label" & N).Caption = rst.Fields(N).Name
Me.Controls("Field" & N).ControlSource = rst.Fields(N).Name
Else
'Hide extra controls.
Me.Controls("Label" & N).Visible = False
Me.Controls("Field" & N).Visible = False
End If
Next N
rst.Close
End Sub
I really need help. Once I have the dynamic report, I'll go back to the
Multiselect list box questions which also gives me trouble. I'm in way over
my head and need help.
Thanks.
this point, I'm trying to create a dynamic crosstab report using code I found
in "Fixing Access Annoyances" by Phil Mitchell and Evan Callahan. My first
four column are static, but the next 6 need to be dynamic (e.g., display 1 or
many). Following is the code which gets "stuck" in the following line -
Set rst = CurrentDb.OpenRecordset(Me.RecordSource).
Don't know if the rest would work, because I don't get very far. Can anyone
please help:
Option Compare Database
Option Explicit
Private Sub Report_Open(Cancel As Integer)
Dim rst As DAO.Recordset
Dim intFields As Integer
Dim intControls As Integer
Dim N As Integer
'Open a recordset for the crosstab query.
Set rst = CurrentDb.OpenRecordset(Me.RecordSource)
' Find the number of text boxes available in the Detail section, minus 4
because we don't count the first 4 row header controls.
intControls = Me.Detail.Controls.Count - 4
' Find the number of fields, minus 4, because we don't count the first 4 row
header filed.
intFields = rst.Fields.Count - 4
' We can't use more than intControls number of fields.
If intFields > intControls Then
intFields = intControls
End If
' Iterate through report fields to set label captions and field control
sources.
For N = 1 To intControls
If N <= intFields Then
Me.Controls("Label" & N).Caption = rst.Fields(N).Name
Me.Controls("Field" & N).ControlSource = rst.Fields(N).Name
Else
'Hide extra controls.
Me.Controls("Label" & N).Visible = False
Me.Controls("Field" & N).Visible = False
End If
Next N
rst.Close
End Sub
I really need help. Once I have the dynamic report, I'll go back to the
Multiselect list box questions which also gives me trouble. I'm in way over
my head and need help.
Thanks.