Я получаю ошибку 3027, я не могу обновить базу данных.Как я могу решить эту ошибку? - PullRequest
0 голосов
/ 03 мая 2019

Я хочу обновить поле «DateEmailSent» в другой таблице, но получаю сообщение об ошибке 3027, в котором говорится, что база данных или объект доступны только для чтения.Он останавливается на rs.Edit.Я попытался rs.LockEdits = False, но это не работает.Как я могу сделать базу данных с возможностью обновления.Первоначально база данных могла обновить это поле, но после создания другой формы я получаю эту ошибку.Может быть, форма блокирует записи?

Option Compare Database

Function SendEmail(sql As String)

Dim oOutLook As Outlook.Application
Dim oEmailItem As Mailitem
Dim currentDate As Date

currentDate = Date

Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset(sql)
If rs.RecordCount > 0 Then
    rs.MoveFirst
    Do Until rs.EOF
    If IsNull(rs!Email) Then
        rs.MoveNext
    Else
        If oOutLook Is Nothing Then
         Set oOutLook = New Outlook.Application
        End If
        Set oEmailItem = oOutLook.CreateItem(olMailitem)
        With oEmailItem
                    .To = rs!Email
                    .CC = "josleasecollection@jos.com.sg"
                    .Subject = "End of Lease Product Collection Notification - " & rs!IDATender & " " & rs!PONumber & " CUSTOMER NAME: " & rs!AgencyName
                    .Body = "Dear Customer, " & vbCr & vbCr & _
                            "Notification of End of Lease Collection" & vbCr & _
                            "This is to inform you that leasing product(s) for PO #" & rs!PONumber & " will be expiring on " & rs!DueDate & vbCr & vbCr & _
                            "For a smooth and seamless collection process, you are required to: " & vbCr & _
                            "  - To appoint a single contact point (Name, email and mobile contacts) for coordination purposes." & vbCr & _
                            "  - To make verifications on the lease items for collection" & vbCr & _
                            "  - To consolidate lease equipment & allocate holding are for onsite work purposes." & vbCr & _
                            "  - To provide site clearance access if there are entry restrictions." & vbCr & _
                            "  - To remove any additional parts (i.e. RAM, Additional HD, Graphic cards) installed in the lease equipment that is not part of the lease contract and BIOS password lock." & vbCr & _
                            "  - To sign off all necessary asset & collection forms upon validations." & vbCr & vbCr & _
                            "Important Terms: " & vbCr & _
                            "  1.  Lease equipment must be return in full and good working condition (with the exception of fair wear & tear)." & vbCr & _
                            "      For Desktop, items to be collected with main unit as follows:" & vbCr & _
                            "      - Power Adapter/Cable, Keyboard, Mouse" & vbCr & vbCr & _
                            "      For Notebook, items to be collected with main unit as follows:" & vbCr & _
                            "      - Power Adapter, Carrying case, Mouse" & vbCr & vbCr & _
                            "      For Monitor, items to be collected with main unit as follows:" & vbCr & _
                            "      - VGA Cable" & vbCr & vbCr & _
                            "  2. Any loss of lease equipment, you are required to immediately inform JOS and we will advise the relevant procedures." & vbCr & _
                            "  3. Collection must be completed no later than 14 days after the expiry of lease. We reserve the right to impose a late return fees (calculated on a daily basis) for any lease equipment." & vbCr & _
                            "  4. JOS will send in onsite engineers for asset verification and assist you. If onsite engineers are not available, JOS will provide a handbook for hard disk removal before collection, to which you shall immediately conduct the hard disk removal at your end." & vbCr & _
                            "  5. JOS shall not be held liable for any non-removal of any additional parts." & vbCr & _
                            "  6. JOS shall be indemnified in the event that collection is unsuccessful by the termination date due to the default or unreasonable delay caused by the customer. " & vbCr & _
                            " Appreciate for your acknowledgement by replying to josleasecollection@jos.com.sg by " & currentDate


                    .Send
                    rs.Edit
                    rs!DateEmailSent = Date
                    rs.Update
        End With
        Set oEmailItem = Nothing
        Set oOutLook = Nothing
        rs.MoveNext
    End If
    Loop
Else

End If
rs.Close
Exit_Function:
Exit Function
End Function

Это код формы, которую я создал.

Private Sub btnUpdateEmail_Click()
On Error GoTo Exit_UpdateEmail
Email_Update:
     Dim db As DAO.Database
     Dim qdf As QueryDef
     Dim sql As String

     Set db = CurrentDb()
     Set qdf = db.QueryDefs("qryUpdateEmail")

     sqlString = "UPDATE Company SET Company.Email = '" & Me.txtNewEmail & "' WHERE Company.ContractNumber = '" & Me.txtContractNumber & "' "
     qdf.sql = sqlString

      If Nz(Me.txtContractNumber, "") = "" Then
        MsgBox "Please enter a contract number"
        Resume Exit_Update
      ElseIf Nz(Me.txtNewEmail, "") = "" Then
        MsgBox "Please enter a new email address"
        Resume Exit_Update
      End If

     qdf.Execute dbFailOnError

      qdf.Close
      CurrentDb.Close

Exit_Update:
Exit Sub

Exit_UpdateEmail:
If Err.Number = 2501 Then
    Resume Exit_Update
Else
    MsgBox Err.Description
    Resume Exit_Update
End If
End Sub

Private Sub homeBtn_Click()
    DoCmd.BrowseTo 2, "HomePageMainFrm"
End Sub

1 Ответ

0 голосов
/ 03 мая 2019

Вы не раскрываете его, но ваш sql содержит запрос выбора, который по какой-то причине не может быть обновлен. Проверьте это:

Set rs = CurrentDb.OpenRecordset(sql)
Debug.Print rs.Updatable
...