Calendar (1 Viewer)

mafhobb

Registered User.
Local time
Today, 11:18
Joined
Feb 28, 2006
Messages
1,245
Ok, so this is what i believe that this code does:
Code:
'           arnelgp
'           The following line checks the current checkin date and compares if it is equal or earlier than the last reservation's checkout
            If current_ID = rs!id And rs!CheckInDate <= last_Date Then
                With Me("lblHoliday" & last_Position)
'            If it is the same, it changes the width of the bar of the previous reservation by reducing it half a day plus 20
                    .Width = .Width - ((DAY_WIDTH \ 2) + 20)
                End With
'           the following code then moves the starting point of the new reservation to the right, half a day plus 20. This would leave a gap of 40 between the ending point and the starting point.
                .Left = EMPLOYEE_COL_WIDTH + Abs(rs!CheckInDate > Me.CalendarStartDate) _
                    * DAY_WIDTH * DateDiff("d", Me.CalendarStartDate, rs!CheckInDate) + ((DAY_WIDTH \ 2) + 20)
'           The following line defines the total length of the bar, but I do not understand why this is necessay as this had been done just a few lines above.
                .Width = lngCtlEnd - .Left
 
            Else
'            'end of arrnelgp
'           This defines the left position of the bar that does not have a previous reservation ending the same day that this one begins.
                .Left = EMPLOYEE_COL_WIDTH + Abs(rs!CheckInDate > Me.CalendarStartDate) _
                   * DAY_WIDTH * DateDiff("d", Me.CalendarStartDate, rs!CheckInDate)
'            The following line defines the width of a reservation that does not have a ending the same day that this one begins.
                .Width = lngCtlEnd - .Left
            End If
 

mafhobb

Registered User.
Local time
Today, 11:18
Joined
Feb 28, 2006
Messages
1,245
Starting points of the calendar bars: Since I want all the reservation's bars to begin at ((DAY_WIDTH \ 2) + 20) then I do not really need to have an IF to check this; I just need to make sure that all the .left for all reservations is at ((DAY_WIDTH \ 2) + 20). I just need to make sure that reservations that are "cut out" from the left (that begin before the starting date of the calendar) show a bar that begins at the edge of the calendar.

Ending points for calendar bars: Since I want all reservation's bars to end at ((DAY_WIDTH \ 2)- 20) then I need to subtract this from all the .width, but again, I need to make sure that this does not affect the reservations on the far right of the calendar.

Now, without taking into account the far left and far right calendar ends, this does what I need:
Code:
                .Left = EMPLOYEE_COL_WIDTH + Abs(rs!CheckInDate > Me.CalendarStartDate) _
                    * DAY_WIDTH * DateDiff("d", Me.CalendarStartDate, rs!CheckInDate) + ((DAY_WIDTH \ 2) + 20)
                .Width = lngCtlEnd - .Left - ((DAY_WIDTH \ 2) + 20)

So now I need to figure out how to do the far left and far right of the calendar and also how to solve an error: "The control or subform control is too large for this location" which I believe that is related to the minimum width of the bar on the far left or far right.

Am I far off?
 

mafhobb

Registered User.
Local time
Today, 11:18
Joined
Feb 28, 2006
Messages
1,245
This is what I've come up with.
The first IF checks where each reservation begin and it compares it with the calendar. If it begins before the calendar star date then the begining of the bar is right at the start of the calendar, otherwise it starts at half the width plus 20
The second if does the same with the end of the calendar
Code:
                If rs!CheckInDate <= Me.CalendarStartDate Then
                     .Left = EMPLOYEE_COL_WIDTH + Abs(rs!CheckInDate > Me.CalendarStartDate) _
                    * DAY_WIDTH * DateDiff("d", Me.CalendarStartDate, rs!CheckInDate)
                Else
                    .Left = EMPLOYEE_COL_WIDTH + Abs(rs!CheckInDate > Me.CalendarStartDate) _
                    * DAY_WIDTH * DateDiff("d", Me.CalendarStartDate, rs!CheckInDate) + ((DAY_WIDTH \ 2) + 20)
                End If
                If rs!CheckOutDate >= CalendarEndDate Then
                    .Width = lngCtlEnd - .Left
                Else
                    .Width = lngCtlEnd - .Left - ((DAY_WIDTH \ 2) + 20)
                End If
Seems to work well!
mafhobb
 

mafhobb

Registered User.
Local time
Today, 11:18
Joined
Feb 28, 2006
Messages
1,245
Now that this is worked out, there are a couple of small things that need attention:

-When double clicking on a reservation bar it is possible to edit the reservation GuestName. I've inadvertantly deleted a number of "GuestNames" with this. Can this double click option be deleted?

- I am not sure what "Search employees" does now. I don't really see a need for this and can probably be deleted. Will this cause any problem?
mafhobb
 

Attachments

  • Calendar V5.1.accdb
    2.3 MB · Views: 115

mafhobb

Registered User.
Local time
Today, 11:18
Joined
Feb 28, 2006
Messages
1,245
Ok, so I found how to do this, but simple commenting out the code in the sub that did this.

That said, I have another question: I added a "close" button on the calendar form. This is a simple
Code:
Private Sub cmdClose_Click()

DoCmd.Close acForm, "Calendar"

End Sub
but something unexpected happens... If only this form is open and I press this button, it closes the form and that's it, however if there is another form open (the one that the calendar opens from), then I get an error "An error ocurred:' DB cannot find the referenced form "Calendar"
For some reason, a private sub called "Private sub form resize()" on form "Calendar" gets going and created this error.
Why would this happen?
mafhobb
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:18
Joined
May 7, 2009
Messages
19,245
can you use:

DoCmd.Close acForm, Me.Name
 

mafhobb

Registered User.
Local time
Today, 11:18
Joined
Feb 28, 2006
Messages
1,245
I don't understand how a closing form could "look for itself" when closing...this has to be code that comes from somewhere else.
 

Minty

AWF VIP
Local time
Today, 17:18
Joined
Jul 26, 2013
Messages
10,371
How are you opening the Calendar form - can you show us the code, including any after the open code?
 

mafhobb

Registered User.
Local time
Today, 11:18
Joined
Feb 28, 2006
Messages
1,245
Well, it is this simple code to open the Calendar form from frmDocumentParameters, whcih stays open in the background:
Code:
Private Sub cmdOpenCalendar_Click()
    DoCmd.OpenForm "Calendar"
End Sub
This is the OnLoad event for Calendar
Code:
Private Sub Form_Load()
Debug.Print Me.Section(acHeader).BackColor
End Sub
This is the OnOpen event for Calendar
Code:
Private Sub Form_Open(Cancel As Integer)
Me.txtCalendarStartDate = Date
Me.CalendarStartDate = Date
Me.RefreshCalendar True, 0, True
End Sub
This is the OnResize event for Calendar:
Code:
Private Sub Form_Resize()
On Error Resume Next
Me.RefreshCalendar False, , True
End Sub
 

Minty

AWF VIP
Local time
Today, 17:18
Joined
Jul 26, 2013
Messages
10,371
I would remove the on error resume next from the form resize event, and see when that is being called.
 

mafhobb

Registered User.
Local time
Today, 11:18
Joined
Feb 28, 2006
Messages
1,245
Still the exact same error, and when accepting it, the message dissapears and all seems to be working well.
Why would the "On Resize" sub be called anyway when closing a form?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:18
Joined
May 7, 2009
Messages
19,245
Edit Module, fn
Edit LogError and change it to:
Code:
Function LogError(ErrMsg)
DoCmd.Echo True
DoCmd.Hourglass False
Screen.MousePointer = 0
If Err <> 2450 Then
    MsgBox "An error occured: " & Err & ", " & ErrMsg, vbExclamation
End If
On Error Resume Next
Forms!Calendar.Painting = True
End Function
 

Users who are viewing this thread

Top Bottom