By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,978 Members | 1,373 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,978 IT Pros & Developers. It's quick & easy.

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

P: 4
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_Click()
Dim myCount As Variant
DoCmd.OpenForm "frmCandSkillsDel", acNormal, "qryCandSkillFilter", , , acDialog
myCount = Selection.Rows.Count
If myCount = -1 Then
DoCmd.Close acForm, "frmCandSkillsDel"
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'
Apr 18 '10 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 305
ADO will return a -1 on the recordcount property WHEN there are records... 0 otherwise... To prevent any confustion I use this if statement...
Expand|Select|Wrap|Line Numbers
  1. If Rs.RecordCount <> 0 And Rs.BOF = False And Rs.EOF = False Then
  2.   'Have Records
  3. Else
  4.   'no records
  5. End If
  6.  


Good Luck
Apr 19 '10 #2

P: 4
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 :-)
Apr 19 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.