DCount fails in subform?

Wegets7

Registered User.
Local time
, 19:22
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

Access 02 Win xp/98
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:
Between these two lines :

End If
If bytResponse = vbYes Then

put the following:


End If
msgbox " Count Equals Zero"
If bytResponse = vbYes Then


what happened?
 
Uncle Gizmo said:
Between these two lines :

End If
If bytResponse = vbYes Then

put the following:


End If
msgbox " Count Equals Zero"
If bytResponse = vbYes Then


what happened?

thanks giz
That section of code is skiped completly. It hits the Dcount statement and goes to the error handler.
 
Is the query "qry_DeleteCopy_CopyEntry" running?
 
Uncle Gizmo said:
Is the query "qry_DeleteCopy_CopyEntry" running?

What I suspect is happening is because the code works when the form is running by itself when the form is a subform the main form is canceling the query in some way.

How do I correct this?
 
The other thing is that subforms are notoriously difficult to access with your code. It depends where your code is, is it on the main form or actually within the subform?

If the code is on the main form then you may wish to try something like this:

If IsNull(childFoundQuote.Form!txtQuoteID) Or _
childFoundQuote.Form.RecordsetClone.RecordCount = 0 Then
msgMessage "Please highlight the Customer that you want to select."

Else

********************

Where "childFoundQuote" Is the name of the subform window on your main form.
 
Uncle Gizmo said:
The other thing is that subforms are notoriously difficult to access with your code. It depends where your code is, is it on the main form or actually within the subform?

If the code is on the main form then you may wish to try something like this:

If IsNull(childFoundQuote.Form!txtQuoteID) Or _
childFoundQuote.Form.RecordsetClone.RecordCount = 0 Then
msgMessage "Please highlight the Customer that you want to select."

Else

********************

Where "childFoundQuote" Is the name of the subform window on your main form.

Its in the subform and I'm not sure how to make the main form respond when a subform button is pressed.

Thanks for your time.
 
Last edited:
Thanks for all your help.
It was a case of oprerator stupidity.

I was referencing the text box value both in the DCount and in the query.
 

Users who are viewing this thread

Back
Top Bottom