Save button (1 Viewer)

ivonsurf123

Registered User.
Local time
Today, 04:36
Joined
Dec 8, 2017
Messages
69
Hello,

Can you please help me to figure why is giving me this error: Syntax Error(Missing Operator) in query expression '()'
What I am trying to do is when user clicks Save, the system will firstly remove all bank holidays in the holiday Flatfile table (for selected country) and replace with what's in the list (selected country). Thank you.

Code:
Dim Response
    Dim rstFF As Recordset
    Dim rstAllocated As Recordset
    Dim rstPH As Recordset
    Dim rstEmployee As Recordset
    Dim rstAttend As Recordset
    
    Dim strFF As String
    Dim strAllocated As String
    Dim strPH As String
    Dim strEmployee As String
    Dim strAttend As String
    Dim sSearch As String
  
    
    
    If Me.cboCountry = "BE" Then
            
            'first remove all entries and update with defaults
            strFF = "Select * from tbl_HolidayTracker_Flatfile where (" & sSearch & ") order by [AttendDate]"
            
            'Debug.Print strFF
            
            Set rstFF = CurrentDb.OpenRecordset(strFF, dbOpenDynaset, dbSeeChanges)
            If rstFF.RecordCount > 0 Then
                rstFF.MoveLast
                rstFF.MoveFirst
                
                While Not rstFF.EOF
                                                            
                    rstFF.Edit
                    
                    rstFF![Contr Hrs] = Format(rstEmployee![FTE % hours per day], "0.00")
                    rstFF![SDP Hrs] = Format(rstAllocated![Standard hours per day] * rstAllocated![SDP], "0.00")
                    rstFF![Other Hrs] = Format(rstAllocated![Standard hours per day] * rstAllocated![Other], "0.00")
                    rstFF![Hours] = Format(rstFF![SDP Hrs] + rstFF![Other Hrs], "0.00")
                    rstFF![Activity] = "A"
                    rstFF![%FTE] = rstEmployee![% FTE] * 100
                    
                    rstFF.Update
                    
                    rstFF.MoveNext
                Wend
                
            End If

            rstFF.Close
            Set rstFF = Nothing
            
            'Now update with new values
            strFF = "Select * from tbl_HolidayTracker_Flatfile where [Location]='" & Me.cboCountry.Column(1, Me.cboCountry.ListIndex) & "'"
            Set rstFF = CurrentDb.OpenRecordset(strFF, dbOpenDynaset, dbSeeChanges)
            If rstFF.RecordCount > 0 Then
                rstFF.MoveLast
                rstFF.MoveFirst

                While Not rstFF.EOF

                    rstFF.Edit

                    rstFF![Contr Hrs] = Format(rstEmployee![FTE % hours per day], "0.00")
                    rstFF![SDP Hrs] = Format(rstAllocated![Standard hours per day] * rstAllocated![SDP], "0.00")
                    rstFF![Other Hrs] = Format(rstAllocated![Standard hours per day] * rstAllocated![Other], "0.00")
                    rstFF![%FTE] = rstEmployee![% FTE] * 100


                     If Me.cboCountry = "BE" Then
                            If InStr(1, Me.cboCountry, "A") = 1 Then
                                rstFF![Hours] = Format(DLookup("[Hours]", "tbl_Register_Hours", "[HoursType]='" & Me.cboCountry & "' and [CountryCode]='" & rstEmployee!Location & "'"), "0.00")
                                rstFF![Activity] = "A"
                            End If

                            rstAttend.AddNew
                            rstAttend!EmployeeID = rstEmployee!EmployeeID
                            rstAttend!Attend = Me.cboCountry
                            rstAttend![Date] = rstFF!AttendDate
                            rstAttend.Update

                    End If

                    rstFF.Update

                    rstFF.MoveNext
                Wend

            End If

            rstFF.Close
            rstEmployee.Close
            rstAllocated.Close
            rstAttend.Close
            rstPH.Close
    End If
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:36
Joined
May 21, 2018
Messages
8,527
Code:
strFF = "Select * from tbl_HolidayTracker_Flatfile where (" & sSearch & ") order by [AttendDate]
Debug.print strFF
Show us the resolved string. The problem is obviously in SSearch
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:36
Joined
May 21, 2018
Messages
8,527
I was assuming Ssearch was being passed into the function but it is a local variable. so it is = to "" as far as I can tell. So your malformed string is

"Select * from tbl_HolidayTracker_Flatfile where () order by [AttendDate]
 

ivonsurf123

Registered User.
Local time
Today, 04:36
Joined
Dec 8, 2017
Messages
69
Good eye MajP! let me fix it if I have more problems I will add more comments. Thank you.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:36
Joined
May 21, 2018
Messages
8,527
always debug.print out your sql strings in code before trying to execute in order to error check. A simple missing space, missing quotation mark, bad name, etc. can mess things up.
 

Users who are viewing this thread

Top Bottom