View Full Version : Runtime Error 3075


boblife42
06-19-2008, 07:03 AM
I am getting a Runtime Error 3075: Invalid use of . ! or () in query expression: tbl_EmployeeShiftInformation.'EmployeeNumber'

EmployeeNumber is a text field so it needs the single quotes.
The full code is below:

StrSQL = "UPDATE tbl_EmployeeShiftInformation set DaysWorkedWK1 ='" & WeekText(1) & "', DaysWorkedWK2 = '" & WeekText(2) & "'" & " WHERE tbl_EmployeeShiftInformation.'EmployeeNumber' = " & Forms!frm_EmployeeSchedule![EmployeeNumber]
Thanks for any help.

tehNellie
06-19-2008, 07:14 AM
your column name should be wrapped in square brackets rather than quotes.

ie tbl_EmployeeShiftInformation.'EmployeeNumber'
should be
tbl_EmployeeShiftInformation.[EmployeeNumber]

You need to wrap the information coming from the form in Quotes, not the column name:

ie
StrSQL = "UPDATE tbl_EmployeeShiftInformation
SET DaysWorkedWK1 ='" & WeekText(1) & "', DaysWorkedWK2 = '" & WeekText(2) & "'" & "
WHERE tbl_EmployeeShiftInformation.[EmployeeNumber] = '" & Forms!frm_EmployeeSchedule![EmployeeNumber] & "'"

boblife42
06-19-2008, 07:22 AM
tehNellie (http://www.access-programmers.co.uk/forums/member.php?u=41880):
This gets a new propblem it asked for a parameter value, I entered an employee number into the parameter and then it said that it will post 210 (the number of employees in the table), I only want to update that specific employee.
This is on a form where a person checks what days an employee works and store that in a text string, and insert it into a specific location in the table.
Below is the full code.

Thank you for the help.
Option Compare Database

Private Sub btn__Close_Click()
DoCmd.Close acForm, "frm_EmployeeSchedule", acSaveNo
DoCmd.OpenForm "frm_EmployeeData", acNormal

End Sub

Private Sub btn_SaveSchedule_Click()
Dim StrSQL As String
Dim WeekNumber As Byte
Dim DayOfWeek As Byte
Dim WeekText(1 To 2) As String
Dim CurrentCheckBox As CheckBox

StrSQL = "UPDATE tbl_EmployeeShiftInformation set DaysWorkedWK1 ='" & WeekText(1) & "', DaysWorkedWK2 = '" & WeekText(2) & "'" & " WHERE tbl_EmployeeShiftInformation.['EmployeeNumber'] = " & Forms!frm_EmployeeSchedule![EmployeeNumber]

For WeekNumber = 1 To 2
For DayOfWeek = 1 To 7
Set CurrentCheckBox = Me("WKDay" & LeadingZero(DayOfWeek + ((WeekNumber - 1) * 7)))
If CurrentCheckBox = 0 Then
WeekText(WeekNumber) = WeekText(WeekNumber) & "X"
Else
WeekText(WeekNumber) = WeekText(WeekNumber) & GetFirstLetterOfDay(DayOfWeek)
End If
Next
Next

DoCmd.RunSQL StrSQL

End Sub

Private Function GetFirstLetterOfDay(DayOfWeek As Byte) As String
Select Case DayOfWeek
Case 1: GetFirstLetterOfDay = "M"
Case 2: GetFirstLetterOfDay = "T"
Case 3: GetFirstLetterOfDay = "W"
Case 4: GetFirstLetterOfDay = "R"
Case 5: GetFirstLetterOfDay = "F"
Case 6: GetFirstLetterOfDay = "S"
Case 7: GetFirstLetterOfDay = "N"
End Select
End Function

Private Function LeadingZero(Num As Byte) As String
If Num < 10 Then LeadingZero = "0" & Num Else LeadingZero = Num
End Function

tehNellie
06-19-2008, 07:34 AM
It's asking for a value because 'employeenumber' isn't a valid column name. you need to drop the quotes from the column name and wrap them round the value coming from your form as per the amended SQL I posted.

again for reference
strsql = "UPDATE tbl_EmployeeShiftInformation set DaysWorkedWK1 ='" & weektext(1) & "', DaysWorkedWK2 = '" & weektext(2) & "'" & " WHERE tbl_EmployeeShiftInformation.[EmployeeNumber] = '" & Forms!frm_EmployeeSchedule![employeenumber] & "'"

boblife42
06-19-2008, 07:43 AM
thank you that worked.