I have been trying to wrap my head around this but I keep spinning my wheels and running into walls trying to get this to work.
So I inheritied this Access database from previous guy in this position, and I am trying to add a button to one of the forms in the file and have that button open a report with some speicific info.
So here is what teh form looks like, it is a employee schedule for the month basically. You can click any day on the calendar and in the list box above you get the duty roster for that day.
Here is the VBA code for that form and I have been trying to reverse engineer it so to speak. I understand that some of the blocks of code are for highlighting the current day or for stating the days in the month.
So I have the button place and have the following code for the "OnClick" event for the button:
But when i click the button it just trys to send dozens of print jobs to the printer and I have to frantically click cancel several times. How do I go about having that button when clicked, opening the report and populating the report with whatever is in the list box on the form at the time, or putting whatever is in that list box, into another list box on the report?
So I inheritied this Access database from previous guy in this position, and I am trying to add a button to one of the forms in the file and have that button open a report with some speicific info.
So here is what teh form looks like, it is a employee schedule for the month basically. You can click any day on the calendar and in the list box above you get the duty roster for that day.
Here is the VBA code for that form and I have been trying to reverse engineer it so to speak. I understand that some of the blocks of code are for highlighting the current day or for stating the days in the month.
Code:
Private Sub PopulateCalendar()
On Error GoTo Err_PopulateCalendar
Dim strFirstOfMonth As String, bytFirstWeekdayOfMonth As Byte, bytBlockCounter As Byte
Dim bytBlockDayOfMonth As Byte, lngBlockDate As Long, ctlDayBlock As TextBox
Dim bytDaysInMonth As Byte, bytEventDayOfMonth As Byte, lngFirstOfMonth As Long
Dim lngLastOfMonth As Long, lngFirstOfNextMonth As Long, lngLastOfPreviousMonth As Long
Dim lngEventDate As Long, bytBlankBlocksBefore As Byte, bytBlankBlocksAfter As Byte
Dim astrCalendarBlocks(1 To 42) As String, db As DAO.Database, rstEvents As DAO.Recordset
Dim strEvent As String
Dim lngSystemDate As Long
Dim ctlSystemDateBlock As TextBox, blnSystemDateIsShown As Boolean
Dim strSQL As String
Dim lngFirstDateInRange As Long
Dim lngLastDateInRange As Long
Dim lngEachDateInRange As Long
Dim strStartTime As String
lngSystemDate = Date
intMonth = objCurrentDate.Month
intYear = objCurrentDate.Year
'lstEvents.Visible = False
'lblEventsOnDate.Visible = False
'lblEventsOn.Visible = True
lblMonth.Caption = MonthAndYear(intMonth, intYear)
strFirstOfMonth = Str(intMonth) & "/1/" & Str(intYear)
bytFirstWeekdayOfMonth = Weekday(strFirstOfMonth)
lngFirstOfMonth = DateSerial(intYear, intMonth, 1)
lngFirstOfNextMonth = DateSerial(intYear, intMonth + 1, 1)
lngLastOfMonth = lngFirstOfNextMonth - 1
lngLastOfPreviousMonth = lngFirstOfMonth - 1
bytDaysInMonth = lngFirstOfNextMonth - lngFirstOfMonth
bytBlankBlocksBefore = bytFirstWeekdayOfMonth - 1
bytBlankBlocksAfter = 42 - (bytBlankBlocksBefore + bytDaysInMonth)
Set db = CurrentDb
'If Me.cboEmployee > 0 Then
'strSQL = "SELECT tblLeaveDetail.Last, tblLeaveDetail.First, tblLeaveDetail.Date, tblLeaveDetail.Shift, tblLeaveCode.TypeID " & _
' "FROM tblLeaveCode INNER JOIN tblLeaveDetail ON tblLeaveCode.TypeID = tblLeaveDetail.TypeID " & _
' "WHERE tblLeaveDetail.Employee_ID = " & Me![cboEmployee] & " and tblLeaveDetail.Date Between " & lngFirstOfMonth & " And " & lngLastOfMonth & _
' " ORDER BY tblLeaveDetail.Shift, tblLeaveCode.TypeID, tblLeaveDetail.Last, tblLeaveDetail.First;"
If Me.cboShift = " " Then
strSQL = "SELECT tblLeaveDetail.Last, tblLeaveDetail.First, tblLeaveDetail.Date, tblLeaveDetail.Shift, tblLeaveCode.TypeID " & _
"FROM tblLeaveCode INNER JOIN tblLeaveDetail ON tblLeaveCode.TypeID = tblLeaveDetail.TypeID " & _
"WHERE tblLeaveCode.TypeID <> ""W"" and tblLeaveCode.TypeID <> ""SA"" and tblLeaveCode.TypeID <> ""OT"" and tblLeaveCode.TypeID <> ""BB"" and tblLeaveCode.TypeID <> ""F"" and tblLeaveDetail.Date Between " & lngFirstOfMonth & " And " & lngLastOfMonth & _
" ORDER BY tblLeaveDetail.Shift, tblLeaveCode.TypeID, tblLeaveDetail.Last, tblLeaveDetail.First;"
Else
strSQL = "SELECT tblLeaveDetail.Last, tblLeaveDetail.First, tblLeaveDetail.Date, tblLeaveDetail.Shift, tblLeaveCode.TypeID " & _
"FROM tblLeaveCode INNER JOIN tblLeaveDetail ON tblLeaveCode.TypeID = tblLeaveDetail.TypeID " & _
"WHERE tblLeaveDetail.Shift = """ & Me![cboShift] & """ and tblLeaveCode.TypeID <> ""W"" and tblLeaveCode.TypeID <> ""SA"" and tblLeaveCode.TypeID <> ""OT"" and tblLeaveCode.TypeID <> ""BB"" and tblLeaveCode.TypeID <> ""F"" and tblLeaveDetail.Date Between " & lngFirstOfMonth & " And " & lngLastOfMonth & _
" ORDER BY tblLeaveDetail.Shift, tblLeaveCode.TypeID, tblLeaveDetail.Last, tblLeaveDetail.First;"
End If
Set rstEvents = db.OpenRecordset(strSQL)
Do While Not rstEvents.EOF
lngFirstDateInRange = rstEvents![Date] '<Substitute for [Start Date]>
If lngFirstDateInRange < lngFirstOfMonth Then
lngFirstDateInRange = lngFirstOfMonth
End If
lngLastDateInRange = rstEvents![Date] '<Substitute for [End Date]>
If lngLastDateInRange > lngLastOfMonth Then
lngLastDateInRange = lngLastOfMonth
End If
For lngEachDateInRange = lngFirstDateInRange To lngLastDateInRange
bytEventDayOfMonth = (lngEachDateInRange - lngLastOfPreviousMonth)
bytBlockCounter = bytEventDayOfMonth + bytBlankBlocksBefore
'<Substitute for [Title]>
If astrCalendarBlocks(bytBlockCounter) = "" Then
astrCalendarBlocks(bytBlockCounter) = "[" & rstEvents![TypeID] & "] " & rstEvents![Last] & ", " & Left$(rstEvents![First], 1) & "."
Else '<Substitute for [Title]>
astrCalendarBlocks(bytBlockCounter) = astrCalendarBlocks(bytBlockCounter) & vbNewLine & _
"[" & rstEvents![TypeID] & "] " & rstEvents![Last] & ", " & Left$(rstEvents![First], 1) & "."
End If
Next lngEachDateInRange
rstEvents.MoveNext
Loop
For bytBlockCounter = 1 To 42 'blank blocks at start of month
Select Case bytBlockCounter
Case Is < bytFirstWeekdayOfMonth
astrCalendarBlocks(bytBlockCounter) = ""
ReferenceABlock ctlDayBlock, bytBlockCounter
'ctlDayBlock.BackColor = 12632256
ctlDayBlock.BackColor = RGB(22, 34, 82)
ctlDayBlock = ""
ctlDayBlock.Enabled = False
ctlDayBlock.Tag = ""
Case Is > bytBlankBlocksBefore + bytDaysInMonth 'blank blocks at end of month
astrCalendarBlocks(bytBlockCounter) = ""
ReferenceABlock ctlDayBlock, bytBlockCounter
'ctlDayBlock.BackColor = 12632256
ctlDayBlock.BackColor = RGB(22, 34, 82)
ctlDayBlock = ""
ctlDayBlock.Enabled = False
ctlDayBlock.Tag = ""
ctlDayBlock.Visible = Not (bytBlankBlocksAfter > 6 And bytBlockCounter > 35)
Case Else 'blocks that hold days of the month
bytBlockDayOfMonth = bytBlockCounter - bytBlankBlocksBefore
ReferenceABlock ctlDayBlock, bytBlockCounter
lngBlockDate = lngLastOfPreviousMonth + bytBlockDayOfMonth 'block's date
If bytBlockDayOfMonth < 10 Then
ctlDayBlock = Space(2) & bytBlockDayOfMonth & _
vbNewLine & astrCalendarBlocks(bytBlockCounter)
Else
ctlDayBlock = bytBlockDayOfMonth & _
vbNewLine & astrCalendarBlocks(bytBlockCounter)
End If
'If this block is the system date, change its color (CFB 1-25-08)
If lngBlockDate = lngSystemDate Then
ctlDayBlock.BackColor = 11206655
ctlDayBlock.ForeColor = 0
Set ctlSystemDateBlock = ctlDayBlock
blnSystemDateIsShown = True
Else
ctlDayBlock.BackColor = RGB(242, 242, 242)
ctlDayBlock.ForeColor = 0
End If
ctlDayBlock.Visible = True
ctlDayBlock.Enabled = True
ctlDayBlock.Tag = lngBlockDate
End Select
Next
'If the system date is in this month, show its events
If blnSystemDateIsShown Then
PopulateEventsList ctlSystemDateBlock
End If
Call PopulateYearListBox
Exit_PopulateCalendar:
Exit Sub
Err_PopulateCalendar:
MsgBox Err.Description, vbExclamation, "Error in PopulateCalendar()"
Call LogErrors(Err.Number, Err.Description, "frmCalendar", "PopulateCalendar() Sub-Routine", "Called from Multiple Locations")
Resume Exit_PopulateCalendar
End Sub
So I have the button place and have the following code for the "OnClick" event for the button:
Code:
Private Sub Command93_Click()
Dim i As Integer
For i = 0 To Me.lstEvents.ListCount - 1
DoCmd.OpenReport "rptDailyETSB"
Next i
End Sub
But when i click the button it just trys to send dozens of print jobs to the printer and I have to frantically click cancel several times. How do I go about having that button when clicked, opening the report and populating the report with whatever is in the list box on the form at the time, or putting whatever is in that list box, into another list box on the report?