0

I want to do "do loop" in vba, but the condition is that the loop occurs until there is no rows in table where "Quantity" variable is empty. But I don't knwo how to check if there are no rows like that. I tried building a query (SELECT COUNT(*) AS COUNT FROM Table WHERE Quantity IS NULL), but I don't know how to refer to this "variable" COUNT in VBA. So what I tried to do is :

Do 
 ....
Loop Until Count = 0

Please help!

  • Are you using DAO or ADO? If you're using DAO, see here for an example: https://stackoverflow.com/questions/11514372/how-do-i-save-the-result-of-an-sql-count-query-with-vba-in-access-2007 – Dai Aug 24 '21 at 14:56

1 Answers1

0

Use DCount:

Count = DCount("*", "[YourTable]", "[Quantity] Is Null")
Gustav
  • 53,498
  • 7
  • 29
  • 55
  • I tried your solution like this: Dim Count ` Count = DCount("*", "[Table]", "[Quantity] Is Null") Do DoCmd.OpenQuery "Record" Loop Until Count <> 0 ` but it didn't stop and it opened this query over and over again ad the Access crushed down. Do you see maybe where I made a mistake? – ArthurMorgan Aug 25 '21 at 05:26
  • Don't know what you try to do. First `Loop Until Count = 0`, now `Loop Until Count <> 0`. Anyway, if the condition never will succeed, the loop will run forever. – Gustav Aug 25 '21 at 08:41