473,569 Members | 2,751 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check if no records returned by query

2 New Member
I have a child combo box whose values depend on a user selected value in the parent combo box. If the child row source query returns no rows, the listcount property still is set to 1 in Access 2003. And if the query returns 1 valid row, the list count is set to 1.

I need to set the enabled = False on the child combo box if there are no valid rows from the query. see vba below.

thks in advance.

Expand|Select|Wrap|Line Numbers
  1. Private Sub ProjCombo_AfterUpdate()
  2. Dim sAcctSource As String, sDeptSource As String
  3. '
  4. sAcctSource = "SELECT ComboMaster.AcctID, ComboMaster.BUnitID, ComboMaster.ProjID, " & _
  5.                 "ComboMaster.ActivityID FROM ComboMaster WHERE (((ComboMaster.AcctID) Is Not Null) " & _
  6.                 "AND ((ComboMaster.BUnitID)=""" & Me.ProjCombo.Column(3) & """) AND " & _
  7.                 "((ComboMaster.ProjID)=""" & Me.ProjCombo.Value & """) AND " & _
  8.                 "((ComboMaster.ActivityID)=""" & Me.ProjCombo.Column(2) & """))"
  9. Me.AcctCombo.RowSource = sAcctSource
  10. Me.AcctCombo.Requery
'
it's here where i check the listcount of acctcombo to determine if i need to hide account combo. problem is that the listcount returns 1 regardless if there are no rows returned by query or 1 valid row.
End Sub
Mar 15 '07 #1
3 26057
Rabbit
12,516 Recognized Expert Moderator MVP
Open a recordset with that SQL and use a .RecordCount.
Expand|Select|Wrap|Line Numbers
  1. Dim rst As Recordset
  2. Set rst = CurrentDb.OpenRecordset("SQL Statement")
  3. If rst.RecordCount = 0 Then ...
  4.  
Mar 16 '07 #2
kpdgsyi
2 New Member
Open a recordset with that SQL and use a .RecordCount.
Expand|Select|Wrap|Line Numbers
  1. Dim rst As Recordset
  2. Set rst = CurrentDb.OpenRecordset("SQL Statement")
  3. If rst.RecordCount = 0 Then ...
  4.  
Thanks Rabbit. Worked like a champ
Mar 16 '07 #3
Rabbit
12,516 Recognized Expert Moderator MVP
Thanks Rabbit. Worked like a champ
Not a problem, good luck.
Mar 16 '07 #4

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

Similar topics

20
10111
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
5
8285
by: Terri | last post by:
I have a form with a multi-select combo. I dynamically build a SELECT statement, open a report, and set the recordsource to my dynamic SELECT statement. I count the records returned in the report by setting a text box to =Count(*). This works fine. Now I want to count the unique records in my report. I can dynamically create a SELECT...
13
3451
by: Jan | last post by:
Hi I have a database that I use to keep track of the sales promotions that we send to companies. I normally send a mailing based on a subset of the companies in the database (found using the query: QryICTMassDistribution3) , I then use a form and the code below to create a new record in the corrispondence table to show what...
5
28046
by: Marcus | last post by:
I have the following code: Private Sub cmdDatasheet_Click() DoCmd.OpenQuery "qryCourse_Details" End Sub I would like to check to make sure that this above query has zero rows, then show a message box that says "There are no results in your query". I can not put the following code in the forms open event but that
3
6634
by: deko | last post by:
Is there any way to limit the number of records loaded into a ListBox? I looked at qdf.MaxRecords (to apply to the query that is the RowSource of the ListBox) but that only applies to ODBC data sources. I also looked at Tools > Options > Edit/Find and tried setting the "Don't display lists where more than this number of records read:"...
30
35843
by: S. van Beek | last post by:
Dear reader A record set can be empty because the condition in the query delivers no records. Is there a VBA code to check the status of a record set, record set empty
7
3745
by: sesling | last post by:
Currently I am using 3 text boxes (status1, status2, status3) on a form and passing the values to a query. The operator will enter one of three statuses (Open, Closed, Pending) in one or more text boxes. The operator will execute a query and the results will be returned based on what they enter. Below I have listed the criteria statement from...
1
1964
by: dfw1417 | last post by:
I have used a query and report filter to return records related to a specific account id. I want to print a report including only the latest 6 records out of the set returned by the record filter. I have set the sort order for the report on descending thus returning the latest records at the top of the report. However since there are well over 6...
0
7609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7666
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6278
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2107
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.