473,320 Members | 1,957 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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_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
2 1238
vb5prgrmr
305 Expert 100+
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
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

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

Similar topics

3
by: dhowell | last post by:
I have a form that has two sub forms. I would like to use the current value of one of the subform fields as a search parameter in a query. I tried pointing to the name of the form/field within...
2
by: allyn44 | last post by:
Hello, I have built a serch form for users to edit records. I only want them to pull up the record they need, and I want to check for nulls. There should not be dupes becasue the underlying...
3
by: kev | last post by:
Hi folks, I have a form for registration (frmRegistration) whereby i have two buttons. One is Save which saves record using the OnClick property. I used wizard to create the save button. The...
14
by: keri | last post by:
Hi, Simple version of the question..... How do I use the where clause of the open form command to show an account with a matching ID to be displayed when the form is opened? Eg. I select a...
3
by: sphinney | last post by:
I have a form with a subform. The code of the parent form alters the "Recordsource" property of a subform. Altering this property automatically triggers the subform to requery a table that has lots...
2
by: fniles | last post by:
I am using VB.NET 2005 and MS Access. I use OLEDbCommand ExecuteNonQuery to delete a record from a database. Whenever the program gets a message, it creates a new thread to process that message....
1
by: mbatestblrock | last post by:
I think I have a rather advanced question that I was hoping to find some good help with. I am still pretty new to VBA and I know that doesn't help my situation here. But here is what I am trying to...
5
by: billa856 | last post by:
Hi, My project is in MS Access 2002. In that I want to open one form multiple times. I put one button on my main form. Now whenever I click on that button than form will be open. Now when I...
5
by: jgarcia187 | last post by:
I have a report that runs based on parameters set in the underlying query. For example, in the "account number" field in the query I've entered in the criteria area. This allows the user to select...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.