Hmmm...
Here's a wee improvement on the code in in my previous post.
It deals with the problem of the number of controls exceeding the maximum
width of the report, and forces them to "wrap" them to a new line...
********************
.....
For Each varItm In ctlListBox.ItemsSelected
strField = ctlListBox.ItemData(varItm)
Set ctlCheckBox = CreateReportControl(rpt.Name, acCheckBox, , ,
strField, intDataX, intDataY)
Set ctlLabel = CreateReportControl(rpt.Name, acLabel, ,
ctlCheckBox.Name, strField, intLabelX, intLabelY)
intLabelX = intLabelX + 1440 'each label is 1" apart
If intLabelX > 7200 Then '7200 = 5 inches (maximum allowed)
intLabelY = intLabelY + 200 'Wrap label to new line
intLabelX = 2880 ' Reset label to intial position, so that it is
aligned with first row
End If
intDataX = intDataX + 1440 'each checkbox is also 1" apart
If intDataX > 8640 Then '8640 = 6 inches (maximum allowed)
intDataY = intDataY + 200 'Wrap checkbox to new line
intDataX = 3880 ' Reset checkbox to intial position, so that it
is aligned with first row
End If
Next varItm
.....
********************
"Don Leverton" <leveriteNoJunkMail@telusplanet.net> wrote in message
news:TRouc.4216$CD4.3323@edtnps84...[color=blue]
> ************************************************** **
> Option Compare Database
> Option Explicit
> Dim MySQL As String 'This is declared in the form's declaration section so
> that it can be used in more than one procedure on this form.
>
> '-------------------------------------------------------------------------
> Private Sub cmdCreateReport_Click()
>
> 'FYI notes that apply to the code below
> '------------------------------------------
> 'Section(0) - Detail Section
> 'Section(1) - Report Header
> 'Section(2) - Report Footer
> 'Section(3) - Page Header
> 'Section(4) - Page Footer
> 'Section(5) - Group Level 1 Header
> 'Section(6) - Group Level 1 Footer
> 'Section(7) - Group Level 2 Header
> '(all sizes in twips)... 1 twip = 1/1440 of an inch
> 'CreateReportControl(reportname, controltype[, section[, parent[,
> columnname[, left[, top[, width[, height]]]]]]])
> ------------------------------------------
>
> sRequerySubform ' Makes sure that the data is up-to-date as of the time[/color]
that[color=blue]
> this button is pressed.
>
> Dim rpt As Report
>
> Dim MyCtl As Control 'Probably could have used this for various control
> types.
> Dim ctlTextBox As Control
> Dim ctlListBox As Control
> Dim ctlLabel As Control
> Dim ctlCheckBox As Control
> Dim varItm As Variant
> Dim strField As String
> Dim intDataX As Integer, intDataY As Integer
> Dim intLabelX As Integer, intLabelY As Integer
>
> Set ctlListBox = Me.lstFieldList
> ' Create new report with tblCustomers as its record source.
> Set rpt = CreateReport
> rpt.RecordSource = MySQL 'Yup same good old SQL string
>
> rpt.Section(0).Height = 500
> rpt.Section(4).Height = 300
> rpt.Width = 9360 '6.5 x 1440 twips/inch
>
> 'Set up the page header section (which is pretty "Plain Vanilla")
> '------------------------------------------------------------------
> Set ctlLabel = CreateReportControl(rpt.Name, acLabel, acPageHeader, , ,[/color]
100,[color=blue]
> 100)
> ctlLabel.Caption = "Whatever you want to call this report."
> ctlLabel.Height = 720
> ctlLabel.Width = 7000
> ctlLabel.FontName = "Times New Roman"
> ctlLabel.FontSize = 18
> Set MyCtl = CreateReportControl(rpt.Name, acLine, acPageHeader, , , 0,[/color]
840,[color=blue]
> 9360)
>
> '----------------------- Create the "fixed" label / textbox
> fields --------------------------
>
> Set ctlTextBox = CreateReportControl(rpt.Name, acTextBox, acDetail, ,
> "FirstName", 1000, 100)
> Set ctlLabel = CreateReportControl(rpt.Name, acLabel, acDetail,
> ctlTextBox.Name, "FirstName", 100, 100)
>
> Set ctlTextBox = CreateReportControl(rpt.Name, acTextBox, acDetail, ,
> "LastName", 1000, 400)
> Set ctlLabel = CreateReportControl(rpt.Name, acLabel, acDetail,
> ctlTextBox.Name, "LastName", 100, 400)
>
> '----------------------- Create the "variable" label / checkbox
> fields --------------------------
> ' Initialize positioning values for the first pair of variable controls.
> intLabelX = 2880
> intLabelY = 100
> intDataX = 3880
> intDataY = 100
> If ctlListBox.ItemsSelected.Count > 0 Then
>
> For Each varItm In ctlListBox.ItemsSelected
> strField = ctlListBox.ItemData(varItm)
> Set ctlCheckBox = CreateReportControl(rpt.Name, acCheckBox, , ,
> strField, intDataX, intDataY)
> Set ctlLabel = CreateReportControl(rpt.Name, acLabel, ,
> ctlCheckBox.Name, strField, intLabelX, intLabelY)
>
> intLabelX = intLabelX + 1440 'each label is 1" apart
> 'intLabelY = 100
> intDataX = intDataX + 1440 'each checkbox is also 1" apart
> 'intDataY = 100
> Next varItm
>
> End If
>
> DoCmd.Maximize ' Maximize the report
> DoCmd.RunCommand acCmdPrintPreview 'Switch to Print Preview mode
>
> End Sub
>
> '-------------------------------------------------------------------------
> Private Sub Form_Open(Cancel As Integer)
> DoCmd.Maximize
> sRequerySubform
> End Sub
>
> '-------------------------------------------------------------------------
> Private Sub lstFieldList_AfterUpdate()
> sRequerySubform
> End Sub
>
> '-------------------------------------------------------------------------
> Public Sub sRequerySubform()
> 'What I want to do here is build the RecordSource for the subform
> 'ON-THE-FLY...to allow for a variable WHERE statement.
> 'in order to alow the user to view:
> ' 1.) ALL records
> ' 2.) filtered by one field only
> ' 3.) filtered by multiple fields
>
> Dim ctl As Control
> Set ctl = Me.lstFieldList
>
> Dim Msg As String
>
> Dim CR As String
> CR = vbCrLf
>
> Dim varItm As Variant
> Dim whr As String
>
> 'Build the SELECT portion of the SQL statement
> MySQL = ""
> MySQL = MySQL & "SELECT tblCustomers.*"
> MySQL = MySQL & " FROM tblCustomers "
>
> 'Build the WHERE portion
> whr = "" 'initialize variable
> If ctl.ItemsSelected.Count > 0 Then
>
> For Each varItm In ctl.ItemsSelected
>
> If Len(whr) > 0 Then
> whr = whr & " OR " & ctl.ItemData(varItm) & "= True"
> Else
> whr = whr & ctl.ItemData(varItm) & "= True"
> End If
>
> Next varItm
>
> End If
>
> If Len(whr) > 0 Then
> MySQL = MySQL & "WHERE (" & whr & ")"
> End If
>
> MySQL = MySQL & "; "
> 'Debug.Print MySQL
>
> Me.sbfCustomers.Form.RecordSource = MySQL
> Set ctl = Nothing
>
> End Sub
>
>
> ************************************************** **
>
> --
> HTH,
> Don
> =============================
> Use
My.Name@Telus.Net for e-mail
> Disclaimer:
> Professional PartsPerson
> Amateur Database Programmer {:o)
>
> I'm an Access97 user, so all posted code
> samples are also Access97- based
> unless otherwise noted.
>
> Do Until SinksIn = True
> File/Save, <slam fingers in desk drawer>
> Loop
>
> ================================
>
>
>[/color]