MichaelRed;
This is what I am looking for! Simple and effective. I can easily modify this to meet the needs of my project once I get the little nasties out of the way
Here are a couple issues I don't understand with this:
1. I am using the ADODB method. Did I properly convert your code from DAO to ADO?
2. Close to the bottom of the code on this line:
DoCmd.Save acReport, OldName
I get a runtime error that says,
Run-time error '2501':
The Save action was canceled.
Thus, this line fails, too:
DoCmd.Rename MyName, acReport, OldName
However, when I close Access it asks me if I want to save the report. Hmm...
Thank you.
MrMajik
I modified the example you posted to meet the needs of the report.
Public Function basDynRpt()
Dim cnn As New ADODB.Connection
Dim rstAssets As New ADODB.Recordset
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.CurrentProject.Path & "\Dit.mdb;"
rstAssets.Open "SELECT * FROM tblAssets", cnn, adOpenKeyset, adLockReadOnly ' adLockOptimistic
Dim rprt As Report
Dim ctrlLbl As Control
Dim XPos As Single
Dim XIncr As Single
Dim YPos As Single
Dim Idx As Integer
Dim HdrCtrl As Control
Dim DtlCtrl As Control
Dim MyName As String
Dim OldName As String
XIncr = 1444
Set rprt = CreateReport
rprt.RecordSource = tblAgency
MyName = "rptTestReport"
rprt.Caption = MyName & " - Report"
OldName = rprt.Name
' rprt.ScaleMode = 5 'Inches
Idx = 0
While Idx < rstAssets.Fields.Count - 10
'Create the Label
Set HdrCtrl = CreateReportControl(rprt.Name, _
acLabel, acPageHeader, "", _
"", XPos, YPos)
With HdrCtrl
.Height = 300
.Name = "lbl" & rstAssets.Fields(Idx).Name
.Caption = rstAssets.Fields(Idx).Name
.ForeColor = 8388608
.FontBold = True
.TextAlign = 1
.Width = Len(rprt.Caption) * 120
End With
'Detail Field
Set DtlCtrl = CreateReportControl(rprt.Name, _
acTextBox, acDetail, "", _
"", XPos, YPos)
With DtlCtrl
.Width = HdrCtrl.Width
.Height = 300
.Name = "txt" & rstAssets.Fields(Idx).Name
.ControlSource = rstAssets.Fields(Idx).Name
.CanGrow = True
.CanShrink = True
.TextAlign = 1
End With
XPos = XPos + (1.01 * HdrCtrl.Width)
Idx = Idx + 1
Wend
rprt.Section("Detail"

.Height = 0
DoCmd.Restore
DoCmd.Save acReport, OldName
DoCmd.Close
DoCmd.Rename MyName, acReport, OldName
rstAgency.Close
cnn.Close
End Function