Not open the form if the query count it is filtered on is 0 (-1)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CharlieUK
    New Member
    • Apr 2010
    • 4

    #1

    Not open the form if the query count it is filtered on is 0 (-1)

    I have a button on a Client form that opens a form with a query as filter. If the query filters no records then the form comes up blank and doesnt even show the close button. Im trying to use code to say if the query count is 0, which is -1 right?, then do not open the form and say a msgbox 'No skills to delete'. My code is below, i keep fiddling with the code but get different errors. the latest error is run time error 424, object required. can anyone help me please to achieve this, below is my code:

    Private Sub btnDelSkillCJ_C lick()
    Dim myCount As Variant
    DoCmd.OpenForm "frmCandSkillsD el", acNormal, "qryCandSkillFi lter", , , acDialog
    myCount = Selection.Rows. Count
    If myCount = -1 Then
    DoCmd.Close acForm, "frmCandSkillsD el"
    End If
    End Sub

    Regards,

    Charles

    PS I also need to do something similar when the form comes up and i use the delete button to delete the last record (which makes the form go blank) to close the form with a msg saying 'No more skills to delete'
  • vb5prgrmr
    Recognized Expert Contributor
    • Oct 2009
    • 305

    #2
    ADO will return a -1 on the recordcount property WHEN there are records... 0 otherwise... To prevent any confustion I use this if statement...
    Code:
    If Rs.RecordCount <> 0 And Rs.BOF = False And Rs.EOF = False Then
      'Have Records
    Else
      'no records
    End If


    Good Luck

    Comment

    • CharlieUK
      New Member
      • Apr 2010
      • 4

      #3
      Thanks 4 that, I actually managed to do it a 3am last night with the DCount() function, but was told this could work 2.

      Once again thanks 4 your responce :-)

      Comment

      Working...