开发者

How do I fix this compile error: "Expected: Expression"

When a user updates the status of an individual case, that change needs to be stamped across all cases under the account number. Within the VB, I am trying to use the following SQL to update the table with the information the user has put into the form.

DoCmd.RunSQL "UPDATE [Main Details] " & _

"SET [Main Details].[Status] = '" & Status & "' " & _

"AND [Main Details].[On Hold] = '" & On Hold & "' " & _

"WHERE   [Main Details].[Account] = '" & Account & "';"

However, I am getting a compilation error, and I suspect it is something to do with "On Hold". How can I correct this? Any help with this will be greatly appreciated.

For context, I am looking at a combo box called "ReportSelection" on a form called "Main Details". Within the "After Update" event procedure, there is the following code:

Private Sub
 ReportSelection_AfterUpdate()

     If ReportSelection = "Enforcement Letter" Or ReportSelection = "Fees
 Letter" Or ReportSelection = "Follow
 On Letter" Or ReportSelection =
 "Reminder Letter BO" Or
 ReportSelection = "Reminder Letter CR"
 Or ReportSelection = "Reminder Letter
 CT" Or ReportSelection = "Reminder
 Letter NNDR" Or ReportSelection =
 "Reminder Letter RTD" Or
 ReportSelection = "Reminder Letter SD"
 Then
                 CmbStatus = "HOLD Until"
                 [On Hold] = Date + 5
             End If

     DoCmd.RunSQL "UPDATE [Main Details] " & _
       "SET [Main Details].[Status] = '" & Status & "' " & _
       "AND [Main Details].[On Hold] = '" & On Hold & "' " & _
       "WHERE   [Main Details].[Account] = '" & Account &
 "';"

     DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
 acMenuVer70

     Select Case Me!ReportSelection

     Case "Write Email"

         DoCmd.OpenForm "CaseEmail", acNormal, , , acFormEdit,
 acWindowNormal

         Exit Sub

     Case "Arrangement Letter"

         Set dbs = CurrentDb

        DoCmd.RunSQL "SELECT * FROM [Arrangements] " & _
             "WHERE [Client]  = '" & Me!Client & "' " & _
             "AND   [Account] = '" & Me!Account & "' " & _
             "AND   [Status]  = 'Made';"

         Set rst = dbs.OpenRecordset(SQL)

         On Error GoTo ArrangementNotFound

         rst.MoveFirst

         ' rst!PaymentCode

         rst.Close
         Set dbs = Nothing

         GoTo RunReport
          ArrangementNotFound:

         rst.Close
         Set dbs = Nothing

         MsgBox "No arrangement has been made for this account"

         Exit Sub

     Case "Reminder Letter", _
         "Reminder Letter BO", _
         "Reminder Letter CR", _
         "Reminder Letter CT", _
         "Reminder Letter NNDR", _
         "Reminder Letter RTD", _
         "Reminder Letter SD", _
         "Enforcement Letter", "Commital Letter"

         If [Status] = "HOLD" Then
             MsgBox "Order is on HOLD", vbExclamation
             Exit Sub
         End If

         If Me![Bailiff Name] <> "" Then
             MsgBox "Order is with " & Me![Bailiff Name], vbExclamation
             Exit Sub
         End If

         If [First Letter] <> 0 Then
             GoTo RunReport
         Else
             MsgBox "Order has not yet been 1st Noticed", vbExclamation
             Exit Sub
         End If

     End Select
      RunReport:

     Select Case Me!ReportSelection

     Case "Details - Account", "Nulla Bona - All Cases", "Arrangement
 Letter"

         WhereCondition = "[Client]='" & Me!Client & "' AND [Account]='" &
 Me!Account & "'"

     Case Else

         WhereCondition = "[Reference]=" & Forms![Main
 Details]!Reference

     End Select

     On Error GoTo InvalidReport

     DoCmd.OpenReport Me![ReportSelection], acViewPreview, ,
 WhereCondition, acWindowNormal

     Select Case Me!ReportSelection

     Case "Council Tax Seizure"

         '*** DO NOTHING ***

     Case "Details"

         If Me!Return Then

             Sleep 1000

          开发者_Go百科   SendKeys "%(fp)v{ENTER}Z:\Returns\" & Me!Client
 & "\" & Trim(Me!Account) & "_" &
 Trim(Me!Summons) & ".pdf{ENTER}", True

             Sleep 500

             DoCmd.Close acReport, Me!ReportSelection, acSaveNo

         End If

     Case "Details - Account"

         If Me!Return Then

             Sleep 1000

             SendKeys "%(fp)v{ENTER}Z:\Returns\" & Me!Client
 & "\" & Trim(Me!Account) &
 ".pdf{ENTER}", True

             Sleep 500

             DoCmd.Close acReport, Me!ReportSelection, acSaveNo

         End If

     Case "Nulla Bona"

         If Me!Return Then

             Sleep 1000

             SendKeys "%(fp)v{ENTER}Z:\Returns\" & Me!Client
 & "\" & Trim(Me!Account) & "_" &
 Trim(Me!Summons) & "NB.pdf{ENTER}",
 True

             Sleep 500

             DoCmd.Close acReport, Me!ReportSelection, acSaveNo

         End If

         DoCmd.OpenReport "Details", acViewPreview, , "[Reference]=" &
 Forms![Main Details]!Reference,
 acWindowNormal

         If Me!Return Then

             Sleep 1000

             SendKeys "%(fp)v{ENTER}Z:\Returns\" & Me!Client
 & "\" & Trim(Me!Account) & "_" &
 Trim(Me!Summons) & ".pdf{ENTER}", True

             Sleep 500

             DoCmd.Close acReport, "Details", acSaveNo

         End If

     Case "Nulla Bona - All Cases"

         If Me!Return Then

             Sleep 1000

             SendKeys "%(fp)v{ENTER}Z:\Returns\" & Me!Client
 & "\" & Trim(Me!Account) &
 "NB.pdf{ENTER}", True

             Sleep 500

             DoCmd.Close acReport, Me!ReportSelection, acSaveNo

         End If

         DoCmd.OpenReport "Details - Account", acViewPreview, ,
 "[Client]='" & Me!Client & "' AND
 [Account]='" & Me!Account & "'",
 acWindowNormal

         If Me!Return Then

             Sleep 1000

             SendKeys "%(fp)v{ENTER}Z:\Returns\" & Me!Client
 & "\" & Trim(Me!Account) &
 ".pdf{ENTER}", True

             Sleep 500

             DoCmd.Close acReport, "Details - Account", acSaveNo

         End If

     Case Else

         '------------------------------------------+
         ' STAMP EACH CASE WITH TYPE OF LETTER SENT |
         '------------------------------------------+

         Set con = Application.CurrentProject.Connection

         SQL = "INSERT INTO [Free Type] ( Reference, [Text], Username ) " & _
             "SELECT DISTINCTROW Reference, '" & _
             ReportSelection & " Sent', '" & _
             [Forms]![Current User]![Initials] & "' " & _
             "FROM [Main Details] " & _
             "WHERE Client  = '" & [Forms]![Main Details]![Client] & "' "
 & _
             "AND   Account = '" & [Forms]![Main Details]![Account] &
 "';"

         con.Execute SQL

     End Select

     Exit Sub

 InvalidReport:

     MsgBox "This report is currently unavailable, please try again later."

End Sub

Also, it is worth mentioning that a similar piece of code works for a different combo box, without any kind of relevant declarations in the code.

Apologies for not providing much context before, this is my first foray into VB, SQL and Access.


The short answer is: Don't use spaces in your field or table names.

It is clear that you are in dire need of an improved understanding of Access fundamentals, but for now I'll just concentrate on getting you over your current hurdle.

When you add a field to a form in access with spaces in the field name, Access silently replaces the spaces with underscores. So the following code should work with your database as it is currently designed:

CurrentDb.Execute "UPDATE [Main Details] " & _
"SET [Main Details].[Status] = '" & Status & "' " & _
", [Main Details].[On Hold] = '" & On_Hold & "' " & _
"WHERE   [Main Details].[Account] = '" & Account & "';", dbFailOnError

I also changed the AND to a comma in your UPDATE statement, replaced DoCmd.RunSQL with CurrentDb.Execute with the dbFailOnError option so that your query won't throw up dialog boxes or fail silently (if you turn off the warnings, as most people do with DoCmd.RunSQL).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜