As I understand this report, it will produce one page to show schedule for a maximum of 34 days. In this example 9/1/2011 through 10/4/2011. Since 10/5/2011 exceeds the max date I did a fix and tried setup for August and it errored on the Left again. So did this fix:
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim lngDuration As Long 'days of tour
Dim lngStart As Long 'start date of tour
Dim lngLMarg As Long
Dim dblFactor As Double
lngLMarg = Me.boxTimeLine.Left
dblFactor = Me.boxTimeLine.Width
lngStart = DateDiff("d", #9/1/2011#, Me.[StartDate])
lngDuration = DateDiff("d", Me.[StartDate], Me.[EndDate] + 1)
'set the color of the bar based on a data value
Me.txtName.BackColor = Me.colorvalue
Me.txtName.Width = 0 'avoid the positioning error
Me.txtName.Visible = False
If Me!EndDate > Me.txtDay1 And Me!StartDate < Me.txtDay1 + 34 Then
Me.txtName.Visible = True
Me.txtName.Left = IIf(lngStart < 0, 0, lngStart) * dblFactor + lngLMarg
Me.txtName.Width = IIf(lngStart + lngDuration > 34, 34 - IIf(lngStart < 0, 0, lngStart), lngDuration) * dblFactor
End If
Me.MoveLayout = False
End Sub
I now see that the boxTimeLine is used only to set variables in the code. These could be hard coded and the box eliminated. Or just set the box as not visible or no outline so it doesn't show on report.
BTW, this code is calculating Left and Width measures in twips. Although you can see inch measures in Access properties, VBA recognizes twips. See http://www.pbdr.com/vbtips/gen/convtwip.htm