Solved Access Upgrade to 365 (2016) getting compile errors and a notice to update a "Function" (1 Viewer)

Podmoma

New member
Local time
Today, 21:45
Joined
Nov 16, 2021
Messages
3
Hi when I load up my Database I get a "compile error.in query relating to an ActiveFileDate and a module called MyCalcHolDays.
When I try to navigate in the database I get this message: Compile Error - The code in this project must be updated for use on 64-bit systems. Please review and update Declare statements and then mark them with the PtrSafe atribute.

The is the coding that it refers to:
Option Compare Database
Option Explicit
'Const TextMerge As String = "merge.txt"
' May 20/2003 - see below comments why txt file name was changed.
Const TextMerge As String = "merge.888"
Public strTemplate As String ' name of last template choosen by user
Private Declare Function GetTempPath Lib "kernel32" _
Alias "GetTempPathA" (ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long

The module is:
Option Compare Database
Option Explicit
'-----------------------------------------------------

'define variables to be used to access the BankHolDate table
Dim dbsThisDatabase As Database
Dim rstDatesTable As DAO.Recordset
Dim strSQL As String

'-------------------------------------------------------------
Public Function myCalcHolDays(prmStartDate, prmEndDate) As Integer
'function to calculate the number of weekdays (Mon-Fri) between two dates, inclusive
'also checks a separate table of bank holiday dates and excludes these dates from the hol total

Dim myDate As Date 'used for the working date
Dim myTotal As Integer 'used to add up the count of days

If IsNull(prmStartDate) Then
'do nothing - this occurs when the user moves the cursor to a new record -
' the calculation appears to be invoked before any data is added as well as afterwards.
Else
myDate = prmStartDate 'set first date as working date
myTotal = 0 'initialise count to zero

'loop to process the dates one by one, from start date to end date
While myDate <= prmEndDate 'keep processing until past the end date

If Weekday(myDate) <> vbSunday And Weekday(myDate) <> vbSaturday Then
'it's not Sat or Sun - so check to see if it's a bank hol
'set the SQL statement to select the current date from the BankHolDate table
strSQL = "SELECT * FROM BankHolDate WHERE BankHolDate.HolDate = DateValue(' " & myDate & " ');"
Set dbsThisDatabase = CurrentDb() 'define the database to be used
Set rstDatesTable = dbsThisDatabase.OpenRecordset(strSQL) 'run the SQL and put result in the Recordset
If rstDatesTable.RecordCount = 0 Then '0 = no records found, 1 = otherwise
myTotal = myTotal + 1 'not a weekend or bank hol, so add to total
End If
End If
myDate = DateAdd("d", 1, myDate) 'next working date (add 1 day)
Wend
'set value to return
myCalcHolDays = myTotal
End If
End Function


Am also unable to get the DateDiff to function when on the main form - keep getting a a message re compile error.
=YearsMonthsDays([StartDate],[LeavingDate])
=Age([BirthDate]) & " years " & AgeMonths([BirthDate]) & " months"

I am basically dead in the water so could really do with some help on this :)
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:45
Joined
Oct 29, 2018
Messages
21,358
Hi. Welcome to AWF!

If you're using API calls, which you seem to be, you'll have to update them to be compatible with 64-bit. Do a search on 64-bit API and "compiler directives" to see some examples.

Here's one example (untested though).
Code:
Private Declare PtrSafe Function GetTempPath Lib "kernel32" _
Alias "GetTempPathA" (ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long
 

Podmoma

New member
Local time
Today, 21:45
Joined
Nov 16, 2021
Messages
3
Hi thankfully I sorted it - I needed to change a "Private Declare Function" to "Private Declare PtrSafe Function" in my coding - works just fine now. Thanks for your response
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:45
Joined
Oct 29, 2018
Messages
21,358
Hi thankfully I sorted it - I needed to change a "Private Declare Function" to "Private Declare PtrSafe Function" in my coding - works just fine now. Thanks for your response
Hi. Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Top Bottom