DCount(domain,query,criteria) fails in subform

Wegets7

Registered User.
Local time
Yesterday, 21:44
Joined
Oct 18, 2004
Messages
40
This is the Click event code for a delete button on a form.
I'm trying to check if the record that is being deleted is active in another table. There should be only one active instance of the record so dcount isn't required, but I don't know any better.

When I run this code in a stand alone form it works fine.

When the form is running as a subform I get the alarm
"You canceled the previous operation"

and it jumps to the error handler.

Any one experienced this before?
Much thanks in advance,Rich
Code:
Private Sub Delete_Coopy_Record_Click()
On Error GoTo Err_Delete_Coopy_Record_Click
    
    Dim strMessage1 As String
    Dim strMessage2 As String
    Dim intStyle As Integer
    Const strTitle As String = "Delete Record?"
    Dim bytResponse As Byte
    Dim Count As Integer

   Count = DCount("CopyKey", "qry_DeleteCopy_CopyEntry", "CopyKey = FK_CopyKey")
   If Count > 0 Then
        intStyle = vbCritical + vbOK + vbDefaultButton1
        strMessage1 = "This copy is checked out and must be checked in before it can be deleted."
        bytResponse = MsgBox(strMessage1, intStyle, strTitle)
    Else:
        intStyle = vbQuestion + vbYesNo + vbDefaultButton2
        strMessage1 = "Are you sure you want to delete the Copy, "
        bytResponse = MsgBox(strMessage1 & Me.CopyID & " " & Me.FK_ISBN, intStyle, strTitle)
    End If
    If bytResponse = vbYes Then
        With DoCmd
            .SetWarnings False
            .RunCommand acCmdDeleteRecord
            .SetWarnings True
        End With
    End If

        
Exit_Delete_Coopy_Record_Click:
    Exit Sub

Err_Delete_Coopy_Record_Click:
    MsgBox Err.Description
    Resume Exit_Delete_Coopy_Record_Click
    
End Sub
 
Last edited:
Wegets,


First, "Count" is a reserved word.

http://support.microsoft.com/kb/209187/EN-US/

But:

Count = DCount("CopyKey", "qry_DeleteCopy_CopyEntry", "CopyKey = " & Me.FK_CopyKey)

Or if the Key is a string:

Count = DCount("CopyKey", "qry_DeleteCopy_CopyEntry", "CopyKey = '" & FK_CopyKey & "'")

Wayne
 

Users who are viewing this thread

Back
Top Bottom