473,503 Members | 1,643 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 26011
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
10083
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
8275
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...
13
3440
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...
5
28032
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...
3
6626
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...
30
35826
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
3727
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...
1
1953
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...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7084
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...
0
7278
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6991
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...
1
5013
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
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 ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
380
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...

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.