Referrencing a combobox from a report

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jmarcrum
    New Member
    • Oct 2007
    • 105

    Referrencing a combobox from a report

    Hey everyone...

    I have a report with 4 labels on it at the top. The first label is lblSunday1, the second is lblSunday2, and so forth...

    I have a small form in my Database called frmReports. On this form I have cmbMonths, cmbYears, and cmbDates.

    If I select June from cmbMonths and 2008 from cmbYears, all of the Sundays for that month and year are populated into cmbDates (column(1), column(2), column(3), and column(4)).

    Here's my trouble...I have in my Rport On Open VBA code this...

    [CODE=VB]Private Sub Report_Open(Can cel As Integer)

    lblSunday1.Capt ion = Forms!frmReport s!cmbDates.Colu mn(1)
    lblSunday2.Capt ion = Forms!frmReport s!cmbDates.Colu mn(2)
    lblSunday3.Capt ion = Forms!frmReport s!cmbDates.Colu mn(3)
    lblSunday4.Capt ion = Forms!frmReport s!cmbDates.Colu mn(4)

    DoCmd.Maximize

    End Sub [/CODE]

    However, I get an error when I try to open the report filtering to those specific cmbDates values.

    Error: DataType Mismatch

    What am I doing wrong?

    Thanks!
  • jmarcrum
    New Member
    • Oct 2007
    • 105

    #2
    Actually I got it working...

    I set up invisible text boxes on my frmReports to hold the Sunday values and then just threw them into the report



    [CODE=VB]Public Function SetTextBoxDutie sDates()

    Dim TargetDate As Date

    TargetDate = CDate(Forms!frm Reports!cmbMont hs & "/1/" & Forms!frmReport s!cmbYears)

    'loop through days of month and populate txt1st
    For i = 1 To GetTextBoxDutie sMonthDays
    If Weekday(TargetD ate) = vbSunday Then _
    Forms!frmReport s!txt1st.Value = TargetDate
    TargetDate = DateAdd("d", 1, TargetDate)
    Next i

    'loop through days of month and populate txt2nd
    For i = 1 To GetTextBoxDutie sMonthDays
    If Weekday(TargetD ate) = vbSunday Then _
    Forms!frmReport s!txt2nd.Value = TargetDate + 0
    TargetDate = DateAdd("d", 1, TargetDate)
    Next i

    'loop through days of month and populate txt3rd
    For i = 1 To GetTextBoxDutie sMonthDays
    If Weekday(TargetD ate) = vbSunday Then _
    Forms!frmReport s!txt3rd.Value = TargetDate + 0
    TargetDate = DateAdd("d", 1, TargetDate)
    Next i

    'loop through days of month and populate txt4th
    For i = 1 To GetTextBoxDutie sMonthDays
    If Weekday(TargetD ate) = vbSunday Then _
    Forms!frmReport s!txt4th.Value = TargetDate + 0
    TargetDate = DateAdd("d", 1, TargetDate)
    Next i

    'loop through days of month and populate txt5th
    For i = 1 To GetTextBoxDutie sMonthDays
    If Weekday(TargetD ate) = vbSunday Then _
    Forms!frmReport s!txt5th.Value = TargetDate + 0
    TargetDate = DateAdd("d", 1, TargetDate)
    Next i

    End Function





    Public Function GetTextBoxDutie sMonthDays()

    TargetDate = CDate(Forms!frm Reports!cmbMont hs & "/1/" & Forms!frmReport s!cmbYears)

    'Exactly 1 week from TargetDate
    TargetDate = DateAdd("ww", 1, TargetDate)

    'Subtract 1 day
    TargetDate = DateAdd("d", -1, TargetDate)

    GetTextBoxDutie sMonthDays = Day(TargetDate)

    End Function



    Private Sub Report_Open(Can cel As Integer)

    lblSunday1.Capt ion = Forms!frmReport s!txt1st.Value
    lblSunday2.Capt ion = Forms!frmReport s!txt2nd.Value
    lblSunday3.Capt ion = Forms!frmReport s!txt3rd.Value
    lblSunday4.Capt ion = Forms!frmReport s!txt4th.Value
    lblSunday5.Capt ion = Forms!frmReport s!txt5th.Value

    DoCmd.Maximize

    End Sub[/CODE]

    Comment

    Working...