Calendar won display beween 2nd & 12th accdb (1 Viewer)

Dreamweaver

Well-known member
Local time
Today, 01:37
Joined
Nov 28, 2005
Messages
2,466
Calendar wont display beween 2nd & 12th accdb

I have been trying to solve this for weeks and finally given up so going to post it.


Ever since I upgraded from mdb to accdb front/back end I have been having the problem where the data is not found for dates between 2nd and 12th of any month all other dates display correctly can somebody take a look at the code and see if they can find what I have done if it's me.
I have attached 2 images the first with the purle boxes is the one I'm having the problem with and the one with green boxes if an older version that works just fine with mdb datafiles with over 18 million records across 15 db's


I can't post the whole db but if need be I can pull the form and it's required items out


Code:
Public Sub PutInData(E)
    Dim sql As String
    Dim F As Form
    Dim Db As DAO.Database
    Dim rs As DAO.Recordset
    Dim I As Integer
    Dim myDate As Date
    Dim Str As String
    Dim Sched As DAO.Recordset
    Dim StrSch As String
    Dim StrMain As String
    Dim Mn As DAO.Recordset
    Dim RMD As DAO.Recordset
    Dim StrRmd As String
    Dim StrD As String
    Dim D As DAO.Recordset
    Dim S As Variant
    Dim StrR As Variant
    Dim pref As DAO.Recordset
    Dim Ev As DAO.Recordset
    Dim StEv As String
On Error GoTo HandleErr
    'Get the defaults
    Set pref = CurrentDb.OpenRecordset("SELECT * FROM StblPreferences", dbOpenSnapshot)
    
    Set F = Forms!frmScheduleCalendar
 
'Empty out the previous month
    For I = 1 To 37
        F("text" & I) = Null
        F("text" & I).BackColor = pref("EmptyCalendarColour")
        F("Day" & I).BackColor = pref("CalenderDateTitle")
    Next I
    
'Construct the record sources for the curret month
    sql = "SELECT * FROM [QryCalenderSlots] WHERE ((MONTH(SlotDate) = " & F!Cmonth & "  AND YEAR(SlotDate)= " & F!Cyear & " AND [Employee]='" & E & "'" & ")) ORDER BY SlotDate;"
    StrRmd = "SELECT * FROM [QryRemindersCalendarDisplay] WHERE ((MONTH(RemindDate) = " & F!Cmonth & "  AND YEAR(RemindDate)= " & F!Cyear & " AND [EmployeeTo]='" & E & "'" & ")) ORDER BY RemindDate;"
    StEv = "SELECT * FROM [QryCalendarEvents] WHERE ((MONTH(EventDate) = " & F!Cmonth & " AND YEAR(EventDate)= " & F!Cyear & ")) ORDER BY EventDate;"

    Set Db = CurrentDb()
    Set rs = Db.OpenRecordset(sql, dbOpenSnapshot)
    Set RMD = Db.OpenRecordset(StrRmd, dbOpenSnapshot)
    Set Ev = Db.OpenRecordset(StEv, dbOpenSnapshot)

'Populate the calendar
        For I = 1 To 37
            If IsDate(F("date" & I)) Then
                myDate = Format(F("date" & I), StrDateFormatExtra)
                If myDate = Format(Date, StrDateFormatExtra) Then F("Day" & I).BackColor = pref("CurrentDateColour")
                rs.FindFirst "SlotDate = #" & myDate & "#"
                If Not rs.NoMatch Then
                    F("text" & I) = "Entries: " & rs!CSlots & vbCrLf
                    F("text" & I).BackColor = pref("FullCalendarColour")
                End If
                RMD.FindFirst "RemindDate = #" & myDate & "#"
                    If Not RMD.NoMatch Then
                        F("Rmd" & I).Visible = True
                        F("text" & I) = F("text" & I) & "Reminder(s): " & RMD!CRemind & vbCrLf
                        F("text" & I).BackColor = pref("FullCalendarColour") '12058551
                    End If
                Ev.FindFirst "EventDate = #" & myDate & "#"
                    If Not Ev.NoMatch Then
                        F("text" & I) = F("text" & I) & Ev!EventName & vbCrLf
                        F("text" & I).BackColor = pref("HolidayColour")
                    End If
            End If
        Next I
        
rs.Close
RMD.Close
Ev.Close
pref.Close
Db.Close

HandleExit:
   Exit Sub
    
    
HandleErr:
    Select Case Err.Number
        Case 2501 'Cancel = True
            Exit Sub
        Case Else
            Call GlobalErrs(Err.Number, Err.Description, Err.Source, "ModCalendar", "Sub: PutInData")
            Resume HandleExit
        Resume
    End Select
End Sub
 

Attachments

  • 2019-01-03.png
    2019-01-03.png
    43.6 KB · Views: 129
  • 2019-01-03 (1).png
    2019-01-03 (1).png
    45.1 KB · Views: 130
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:37
Joined
May 21, 2018
Messages
8,529
can you put a debug.print to see if the records are being found? I could be a case of forecolor and backcolor being the same so that the data is there and being populated just not visible.
 

Dreamweaver

Well-known member
Local time
Today, 01:37
Joined
Nov 28, 2005
Messages
2,466
The records are in the recordsets but the findfirst Wont find them for the dates I indecated


It's the same with all 3 reordsets
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:37
Joined
May 21, 2018
Messages
8,529
Is that Margate UK or US? If UK I would be concerned about regional settings and could have manifested with upgrade. When working with SQL dates you need to put everything in MM/DD/YYYY format. There are several places this could fail in your code.

can you debug.print the sql strings.
 

Dreamweaver

Well-known member
Local time
Today, 01:37
Joined
Nov 28, 2005
Messages
2,466
I did try that again and only the 4 dates in the attached image are in the printout

Code:
                If Not rs.NoMatch Then
                    Debug.Print "Entries: " & rs!CSlots
                    F("text" & I) = "Entries: " & rs!CSlots & vbCrLf
                    F("text" & I).BackColor = pref("FullCalendarColour")
                End If
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:37
Joined
May 21, 2018
Messages
8,529
I wrap the myDate in a format function to put it into SQL date format
"RemindDate = #" & myDate & "#"
 

Dreamweaver

Well-known member
Local time
Today, 01:37
Joined
Nov 28, 2005
Messages
2,466
Is that Margate UK or US? If UK I would be concerned about regional settings and could have manifested with upgrade. When working with SQL dates you need to put everything in MM/DD/YYYY format. There are several places this could fail in your code.

can you debug.print the sql strings.


I use StrDateFormatExtra for a short date format as I have had that problem before but have had the same problems with using a format of dd/mm/yyyy or short date


have also made sure the same format is used for the tables when posting and my systems settings are dd/mm/yyyy


but it works for one db but not the accdb.


I do intent updating the other db for the coulours ect to see if it causes any problems in that db
 

Dreamweaver

Well-known member
Local time
Today, 01:37
Joined
Nov 28, 2005
Messages
2,466
I wrap the myDate in a format function to put it into SQL date format
"RemindDate = #" & myDate & "#"


Thats set here:


myDate = Format(F("date" & I), StrDateFormatExtra)

But will try it thanks
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:37
Joined
May 21, 2018
Messages
8,529
You do not have to wrap it, if that done with strDateFormatExtra. So is StrDateFormatExtra "MM/DD/YYYY?" Can you debug.print mydate, to show an example?
You said it only finds 4. Can you do a recordcount of rs to see how many records are returned by the query before you do findfirst.
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:37
Joined
May 21, 2018
Messages
8,529
If I was debugging I would try all of these debug.print to see if I could see what is going on
Code:
'Construct the record sources for the curret month
    sql = "SELECT * FROM [QryCalenderSlots] WHERE ((MONTH(SlotDate) = " & F!Cmonth & "  AND YEAR(SlotDate)= " & F!Cyear & " AND [Employee]='" & E & "'" & ")) ORDER BY SlotDate;"
    StrRmd = "SELECT * FROM [QryRemindersCalendarDisplay] WHERE ((MONTH(RemindDate) = " & F!Cmonth & "  AND YEAR(RemindDate)= " & F!Cyear & " AND [EmployeeTo]='" & E & "'" & ")) ORDER BY RemindDate;"
    StEv = "SELECT * FROM [QryCalendarEvents] WHERE ((MONTH(EventDate) = " & F!Cmonth & " AND YEAR(EventDate)= " & F!Cyear & ")) ORDER BY EventDate;"
    debug.print "Sql " & sql    
    debug.print "StrRMD " & strRMD
    debug.print "StEv " & stEv

    Set Db = CurrentDb()
    Set rs = Db.OpenRecordset(sql, dbOpenSnapshot)
    Set RMD = Db.OpenRecordset(StrRmd, dbOpenSnapshot)
    Set Ev = Db.OpenRecordset(StEv, dbOpenSnapshot)
    if not (rs.eof and Rs.BOF) then
      rs.movelast
      rs.moveFirst
      debug.print "rs" & rs.recordcount 
    end if
'Populate the calendar
        For I = 1 To 37
            If IsDate(F("date" & I)) Then
                myDate = Format(F("date" & I), StrDateFormatExtra)
                debug.print "My Date " & myDate
                If myDate = Format(Date, StrDateFormatExtra) Then F("Day" & I).BackColor = pref("CurrentDateColour")
                debug.print "Find First " & "SlotDate = #" & myDate & "#"
                rs.FindFirst "SlotDate = #" & myDate & "#"
                If Not rs.NoMatch Then
                    F("text" & I) = "Entries: " & rs!CSlots & vbCrLf
                    F("text" & I).BackColor = pref("FullCalendarColour")
                End If
                debug.print "RMD " & "RemindDate = #" & myDate & "#"
                RMD.FindFirst "RemindDate = #" & myDate & "#"
                    If Not RMD.NoMatch Then
                        F("Rmd" & I).Visible = True
                        F("text" & I) = F("text" & I) & "Reminder(s): " & RMD!CRemind & vbCrLf
                        F("text" & I).BackColor = pref("FullCalendarColour") '12058551
                    End If
                debug.print "Ev " & "EventDate = #" & myDate & "#"
                Ev.FindFirst "EventDate = #" & myDate & "#"
                    If Not Ev.NoMatch Then
                        F("text" & I) = F("text" & I) & Ev!EventName & vbCrLf
                        F("text" & I).BackColor = pref("HolidayColour")
                    End If
            End If
        Next I
        
rs.Close
RMD.Close
Ev.Close
pref.Close
Db.Close
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:37
Joined
May 21, 2018
Messages
8,529
Because it works on the MDB and not the accdb, my first guess would be something with the date format or something with the color. But it sounds as if you are not returning the correct records so that sounds more like a data issue.
 

Dreamweaver

Well-known member
Local time
Today, 01:37
Joined
Nov 28, 2005
Messages
2,466
Because it works on the MDB and not the accdb, my first guess would be something with the date format or something with the color. But it sounds as if you are not returning the correct records so that sounds more like a data issue.


Been over all the queries and tables one of which is the same in both databases I just imported it but as I said it worked until I upgraded the db to accdb.


thanks for the help off to bed now catch you all tomorrow thanks
 

Dreamweaver

Well-known member
Local time
Today, 01:37
Joined
Nov 28, 2005
Messages
2,466
This is the result of the
debug.print "My Date " & myDate


My Date 01/01/2019
My Date 02/01/2019
My Date 03/01/2019
My Date 04/01/2019
My Date 05/01/2019
My Date 06/01/2019
My Date 07/01/2019
My Date 08/01/2019
My Date 09/01/2019
My Date 10/01/2019
My Date 11/01/2019
My Date 12/01/2019
My Date 13/01/2019
My Date 14/01/2019
My Date 15/01/2019
My Date 16/01/2019
My Date 17/01/2019
My Date 18/01/2019
My Date 19/01/2019
My Date 20/01/2019
My Date 21/01/2019
My Date 22/01/2019
My Date 23/01/2019
My Date 24/01/2019
My Date 25/01/2019
My Date 26/01/2019
My Date 27/01/2019
My Date 28/01/2019
My Date 29/01/2019
My Date 30/01/2019
My Date 31/01/2019


Is the something else I can use instead of findfirst I don't really want to use dcount as I already have a recordset but might try it to see if it can find the records for the dates I'm having problems with.
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:37
Joined
May 21, 2018
Messages
8,529
So the question is if RS is returning the correct records or if the findfirst is failing. You could also debug here to see what date are returned.
Code:
              'do you get the correct records
              do while not rs.eof
                 debug.print "RS " & rs!SlotDate
              rs.movenext
              loop
              'is find first correct
              debug.print "Find First " & "SlotDate = #" & myDate & "#"
              rs.FindFirst "SlotDate = #" & myDate & "#"
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:37
Joined
May 21, 2018
Messages
8,529
Code:
My Date 01/01/2019
My Date 02/01/2019
My Date 03/01/2019
My Date 04/01/2019
My Date 05/01/2019
My Date 06/01/2019
My Date 07/01/2019
My Date 08/01/2019
My Date 09/01/2019
My Date 10/01/2019
My Date 11/01/2019
My Date 12/01/2019
My Date 13/01/2019
My Date 14/01/2019
My Date 15/01/2019
My Date 16/01/2019
My Date 17/01/2019
My Date 18/01/2019
My Date 19/01/2019
My Date 20/01/2019
My Date 21/01/2019
My Date 22/01/2019
My Date 23/01/2019
My Date 24/01/2019
My Date 25/01/2019
My Date 26/01/2019
My Date 27/01/2019
My Date 28/01/2019
My Date 29/01/2019
My Date 30/01/2019
My Date 31/01/2019

Well that is not correct and likely to fail. Sql has to use a mm/dd/yyyy format.
http://allenbrowne.com/ser-36.html

2. Wrong Formatting in Code
In VBA code, delimit dates with the "#" symbol. Regardless or your regional settings, Access expects these literal dates to be in the American format, e.g. #12/31/1999#.

To demonstrate this, enter any date in the Criteria row under a date field in Query Design, and then switch to SQL View. In Query Design view, you see the date according to your local settings, but the SQL statement uses mm/dd/yyyy format.

SQL clauses are not always obvious, e.g. the Filter of a form, the WhereCondition of OpenReport, or the third argument of a domain aggregate function. Examples:

DoCmd.OpenReport "MyReport", acViewPreview, , "InvoiceDate > #12/31/2000#"
Debug.Print DLookup("StudentID", "tblStudent", "EntryDate = #6/30/1953#")
strSQL = "SELECT * FROM tblDonation WHERE DonationDate > #" & Format(Me.StartDate, "mm\/dd\/yyyy") & "#;"
The third example demonstrates how to concatenate a date into a SQL string. The Format() function is essential to force the date into American format. Unfortunately, Format() replaces the slashes with the date separator character defined in Control Panel | Regional Settings, so you must specify literal slashes in the format string by preceding the slash with backslashes.

Since this is something you do frequently, you may find it easy to call a small wrapper function for concatenating date strings. The example below formats it as:

Function SQLDate(varDate As Variant) As String
'Purpose: Return a delimited string in the date format used natively by JET SQL.
'Argument: A date/time value.
'Note: Returns just the date format if the argument has no time component,
' or a date/time format if it does.
'Author: Allen Browne. allen@allenbrowne.com, June 2006.
If IsDate(varDate) Then
If DateValue(varDate) = varDate Then
SQLDate = Format$(varDate, "\#mm\/dd\/yyyy\#")
Else
SQLDate = Format$(varDate, "\#mm\/dd\/yyyy hh\:nn\:ss\#")
End If
End If
End Function
 

isladogs

MVP / VIP
Local time
Today, 01:37
Joined
Jan 14, 2017
Messages
18,235
As MajP has explained, all UK dates have to be explicitly converted to mm/dd/yyyy format to ensure they are correctly interpreted in SQL statements.

Unless you do so 02/01/2019 is treated as 1 Feb, 03/01/2019 as 1 Mar etc all the way to 12/01/2019 being treated as 1 Dec. Where there is any ambiguity, Access assumes the dates are mm/dd/yyyy.

01/01/2019 is Ok as swopping the order has no effect
Just to confuse things, dates from 13/01/2019 to 31/01/2019 will be treated correctly as they are unambiguous dates. In trying to be 'helpful', Access just causes confusion as the results sometimes work.

In Feb, the same issues occur except 02/02/2019 will be ok. Ditto 03/03 etc

In the UK, always format dates as mm/dd/yyyy in sql statements
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:37
Joined
May 21, 2018
Messages
8,529
So I am curious in why this would have ever worked in older MDB.
 

Dreamweaver

Well-known member
Local time
Today, 01:37
Joined
Nov 28, 2005
Messages
2,466
Just run the following against the recordset
Code:
    Do While Not rs.EOF
        Debug.Print "Date: " & rs("SlotDate") & " Slots " & rs("CSlots")
        rs.MoveNext
    Loop


And got the following dates returned



Date: 01/01/2019 Slots 10
Date: 02/01/2019 Slots 6
Date: 03/01/2019 Slots 11
Date: 04/01/2019 Slots 4
Date: 05/01/2019 Slots 8
Date: 10/01/2019 Slots 3
Date: 11/01/2019 Slots 4
Date: 12/01/2019 Slots 2
Date: 13/01/2019 Slots 3
Date: 14/01/2019 Slots 3
Date: 24/01/2019 Slots 3
Date: 31/01/2019 Slots 8


Just thought I would try it while a was thinking about it in the bath
All the records I would expect are on the list if you check against the first image you will see whats missing.


I'll go though the form again tomorrow and thanks for the allen browne info I will read it tomorrow but all the dates from the recordset are being returned in uk format.


thanks
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:37
Joined
May 21, 2018
Messages
8,529
Add this

Code:
Function SQLDate(varDate As Variant) As String
   'Purpose: Return a delimited string in the date format used natively by JET SQL.
   'Argument: A date/time value.
   'Note: Returns just the date format if the argument has no time component,
   ' or a date/time format if it does.
   'Author: Allen Browne. allen@allenbrowne.com, June 2006.
   If IsDate(varDate) Then
      If DateValue(varDate) = varDate Then
        SQLDate = Format$(varDate, "\#mm\/dd\/yyyy\#")
      Else
        SQLDate = Format$(varDate, "\#mm\/dd\/yyyy hh\:nn\:ss\#")
      End If
   End If
End Function

Then
myDate = Format(F("date" & I), StrDateFormatExtra)
becomes
myDate = SQLDate(F("date" & I))

wherever you use strDateFormatExtra
 

Dreamweaver

Well-known member
Local time
Today, 01:37
Joined
Nov 28, 2005
Messages
2,466
thanks for the info it's late now but will try reformating the data tomorrow
 

Users who are viewing this thread

Top Bottom