Error at .update: The expression On click you entered as the event property

GK in the UK

Registered User.
Local time
Today, 21:55
Joined
Dec 20, 2017
Messages
281
Just returned to an old project after a hiatus, and a re-install of Windows 10 64-bit and a fresh download of the latest Access 2016.
the error "The expression On click you entered as the event property setting produced the following error". There's no error number


The error is immediately prior to an .update after doing .AddNew to a DAO.Recordset


I have similar code in two forms with similar code, and Access errors on each form immediately prior to .update. So it's a bit hard to think both forms are corrupted. The code on one of the forms (which has been copied and tweaked to suit a new form) was working in the past but I can't say at what point it failed. But I can see by a MsgBox I've got in the old code, just prior to the .update, that it probably gave me trouble before - I just can't remember how I fixed it.


The file and record handling elsewhere works correctly.


I've tried a decompile, opened a brand new database and imported all the tables, forms and queries. The error remains.


The Microsoft Office 16 Database engine is checked in References (Which I've read now includes support for .DAO)


Really stuck with this one, can anyone help ?
 
try compiling the code first to see if there are more errors.
 
I think I've re-compiled the code several times, but how would I know? I've done the MSACCESS / decompile but either nothing is happening or something happens instantly. How does Access know which file I mean? Anyway the Debug/Compile command was available (not greyed out) when I re-opened so I presume it had done its job.


I run MSACCESS/decompile
Open my project file
Close Access immediately


Re-open my project file
Ctrl-G, Debug, Compile. Actually there is a progress bar but you have to be quick ...


I've also done the compact database thing as well
 
did you put in each module:

Option Explicit

then compile the code.
 
Every module starts with


Option Compare Database
Option Explicit


My feeling is that it isn't the code it's something to do with the library for .DAO, but other .DAO file routines are still working

Scroll to the end to see where it fails. "About to Bookmark" never appears

Code:
Private Function PartDuplicateDocument(bReverse As Boolean)
    ' This is the event handler for two buttons, Duplicate or Reverse
    ' if bReverse = 0, this is a duplicate not reversed
    ' reverse:  test the 0.  interpreted as false.
    ' Create a new document entry with only the tagged lines
    ' The new document is placed in the daybook for editing
    
    Dim db As DAO.Database
    Dim rsHeader As DAO.Recordset
    Dim rsTLsource As DAO.Recordset
    Dim rsTLtarget As DAO.Recordset
'' tried this still doesn't work
''    Dim db As Database
''    Dim rsHeader As Recordset
''    Dim rsTLsource As Recordset
''    Dim rsTLtarget As Recordset
    
    Dim lngNewHeaderID As Long
    Dim strOldDocRef As String      ' eg "PINV1234567"
    Dim strNewDocRef As String      ' eg "PINV1234959"
    Dim strSQL As String
    Dim strSourceText As String     ' eg "PINV1234567 Part Duplicated"
    Dim intResponse As Integer
    Dim intKeepSourceTags As Integer
    Dim intLineNumber As Integer    ' line number within the document
    Dim curNewNetValue As Currency
    Dim curNewNetTotal As Currency
    Dim curNewVatValue As Currency
    Dim curNewVatTotal As Currency
    Dim lngLinesTagged As Integer   ' number of lines that are tagged
    Dim lngCurrentRec As Long       ' the existing document that we're editing
            
    Set db = CurrentDb
    strSQL = "Select * from tblTransLines where tlTransHeaderFK = " & Me!TransHeaderID
    strSQL = strSQL & " Order by tlLineNumber"
    
    lngCurrentRec = Me!TransHeaderID        ' the document we're editing
    ' First we need to see if any lines are tagged.  We don't want to save an empty document
    lngLinesTagged = fTaggedLineCount(lngCurrentRec)
    
    ' don't perform this routine if the document header isn't valid
    ' we get an error at the end once Access has tried to auto-save
    If lngLinesTagged > 0 Then
      If fFormIsValid Then
  
'--------------------------------------------------------------------------------
' Preliminary Confirmation to Proceed with Duplication or Reversal
'--------------------------------------------------------------------------------
  
        Select Case bytPurchCurrentTab
            Case 0      ' templates
                If Not bReverse Then
                    intResponse = MsgBox _
                     ("Create new template with " & lngLinesTagged & " tagged line(s) ?", _
                        vbYesNo, "Duplicate Template Lines")
                Else
                 intResponse = MsgBox _
                     ("Create new template with " & lngLinesTagged & " tagged line(s) reversed ?", _
                        vbYesNo, "Reverse Template Lines")
                End If
            Case 3 To 4 ' documents daybook or posted can be duplicated or reversed
                If Not bReverse Then
                    intResponse = MsgBox _
                     ("Create new document with " & lngLinesTagged & " tagged line(s) ?", _
                        vbYesNo, "Duplicate document Lines")
                Else
                    intResponse = MsgBox _
                     ("Create new document with " & lngLinesTagged & " tagged line(s) reversed ?", _
                        vbYesNo, "Reverse document Lines")
                End If
            Case Else
        End Select


        If intResponse = vbYes Then
        
'--------------------------------------------------------------------------------
' Add Transaction Header for the Duplicated or Reversed document
'--------------------------------------------------------------------------------


            ' We can optionally keep the tags in the existing document header instead of clearing them
            intKeepSourceTags = MsgBox("Retain tags in the existing document ?", vbYesNo, "Retain tags")
            
            Set rsHeader = db.OpenRecordset("tblTransHeaders", dbOpenDynaset)
            
'MsgBox ("1")
            
            With rsHeader
            
                rsHeader.AddNew                             ' prepare a new document header
                
                Select Case bytPurchCurrentTab
                    Case 0
                        strNewDocRef = fNextDocRef("PTEM")  ' fetch a new template ref
                    Case 3 To 4
                        strNewDocRef = fNextDocRef("PINV")  ' fetch a new invoice ref
                    Case Else
                End Select
  
                strOldDocRef = Me.thDocReference            ' we save this to add narrative
                strSourceText = strOldDocRef                ' "Purch1234567"
                
                If bReverse Then
                    strSourceText = strSourceText & " Reversed"
                Else
                    strSourceText = strSourceText & " Duplicated"
                End If
                
                '!TransHeaderID =                           ' Access deals with this
                !thCustSuppFk = Me.thCustSuppFk             ' same customer
                !thDelAddrFK = Me.thDelAddrFK               ' same delivery address
                '!thDocType =
                !thDocReference = strNewDocRef              ' the new document ref eg. PINV1234959
                !thDate = Date                              ' always today's date
                '!thDueDate =
                !thPeriod = Me.thPeriod
                !thYear = Me.thYear
                !thText1 = Me.thText1
                !thText2 = Me.thText2
                !thPostingBatchNo = 0                       ' goes in the daybook for editing
                !thYourOrderRef = strSourceText             ' we use this field to store source details
                '!thAlternativeRef =
                !thText1 = ""
                !thText2 = ""
                !thShippingMethod = ""
                '!thNetValue_summed =                       ' see below
                '!thCostValue_summed =
                thTaggedLines_summed = 0                    ' all turned off for new record
                '!thVatValue_summed =                       ' see below
                !thSettDisc_summed = 0
                !thAllocatedValue_summed = 0
                !thWeight_summed = 0
                '!thStatus =
                !thAuth2Post = 0
                !thAutoReverse = 0
                !thAuth2Pay = 0
                !thReconciled = 0
                !thTagged = 0
                !thPrinted = 0
                !thDateAdded = Now()
                '!thUserAdded =
                'thDateEdited =
                'thUserEdited =
  MsgBox ("About to .update")
                rsHeader.Update                             ' write the new document header FAILS
  MsgBox ("About to .bookmark")
                .Bookmark = rsHeader.LastModified           ' This line IS required not sure why !!
  
                ' we should now have the new AutoNumber key that we need
                lngNewHeaderID = rsHeader!TransHeaderID     ' the new auto number that we need


'--------------------------------------------------------------------------------
' Copy or Reverse Transaction Lines for the Duplicated or Reversed document
'--------------------------------------------------------------------------------
 
debug your code, press F9 on the function, run your form, when it stop at the code, press f8 to step.
 
OK thank you, I've stepped right through from the beginning of the function and it goes no further than the line


rsheader.update


That line is highlighted and I can go no further
 
can you move your rsHeader.AddNew just after the last If..End If.
and since it is enclosed in With rsHeader, you can just use:

.AddNew
.Update
 
Yes the .AddNew and .Update lines were in scope, I added the rs.header in case there was an ambiguity. I didn't have that in before.



I've move the .AddNew command as you suggested, and it's worked ! Not sure why it didn't work as before, but it's fixed, thanks so much
 

Users who are viewing this thread

Back
Top Bottom