Microsoft Access can't find the field 'Weekday' referred to in your expression. (1 Viewer)

dms

New member
Local time
Today, 12:02
Joined
Sep 29, 2017
Messages
3
Hello,

when running the below code the expression "WeekdayName(Weekday(strIn, 2), True, 2)" is causing the following error: "Microsoft Access can't find the field 'Weekday' referred to in your expression."

I use exactly the same expression in 2 other forms in this database without any issues and just can't figure out what this problem is in this case.

Any assistance would be much appreciated.



Private Sub Quick_Log_In()
Dim db As DAO.Database
Dim rsTimeSheet As DAO.Recordset
Dim strWorkingCode, strYear, strMonth, strWeekNbr, strWeekday, strIn As String
On Error GoTo Err_Quick_Log_In

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

strWorkingCode = DLookup("[Default working code]", "tblEmployee", "[Name] = """ & strEmployee & """")
strEmployer = DLookup("[Employer]", "tblEmployee", "[Name] = """ & strEmployee & """")


strIn = Me.In

strTSRecID = Me.ID
strYear = DatePart("yyyy", strIn, 2, 2)
strMonth = DatePart("m", strIn, 2, 2)
strWeekNbr = DatePart("ww", strIn, 2, 2)

'########## Weekday expression issue ##########
strWeekday = WeekdayName(Weekday(strIn, 2), True, 2)
'########## Weekday expression issue ##########

If Len(strMonth) < 2 Then
strMonth = "0" & strMonth
End If

If Len(strWeekNbr) < 2 Then
strWeekNbr = "0" & strWeekNbr
End If


Set db = CurrentDb()

Set rsTimeSheet = db.OpenRecordset("tblTimeSheetRecords", dbOpenDynaset)
If Not (rsTimeSheet.EOF = True And rsTimeSheet.BOF = True) Then
rsTimeSheet.MoveFirst
rsTimeSheet.FindFirst "[ID] =" & strTSRecID

rsTimeSheet.Edit
rsTimeSheet("Employee") = strEmployee
rsTimeSheet("Employer") = strEmployer
rsTimeSheet("Working code") = strWorkingCode
rsTimeSheet("In") = strIn
rsTimeSheet("Hours") = 0
rsTimeSheet("Hrs") = "0"
rsTimeSheet("Mins") = "00"
rsTimeSheet("Week day") = strWeekday
rsTimeSheet("Week number") = strWeekNbr
rsTimeSheet("Month") = strMonth
rsTimeSheet("Year") = strYear
rsTimeSheet.Update
rsTimeSheet.Close
Set rsTimeSheet = Nothing
End If


Exit_Quick_Log_In:
Exit Sub

Err_Quick_Log_In:
MsgBox Err.Description
Resume Exit_Quick_Log_In

End Sub
 

dms

New member
Local time
Today, 12:02
Joined
Sep 29, 2017
Messages
3
My first suspicion is a reference issue:


Hi Paul,

Many thanks.
I checked the references and non are missing and I refreshed them as suggested in the article.
Unfortunately that didn't resolve the problem.
The odd thing is that the same expression works in a different form in the same database and I assume that references apply to the entire DB.
 

Minty

AWF VIP
Local time
Today, 12:02
Joined
Jul 26, 2013
Messages
10,371
Try copying your code to notepad or similar, delete the code module. Compact and repair. recreate the code module calling it something different, paste back your code. Now try it.
 

dms

New member
Local time
Today, 12:02
Joined
Sep 29, 2017
Messages
3
Hello,

that was more or less what I just did.
I remembered I had copied the form rather than having created a new one initially, so I just created a new form and copied the code.
It is working now.

Many thanks.
 

Users who are viewing this thread

Top Bottom