Iff Statement based on record count

Dear Experts

I am building a news letter database which will send out various stories which have been categorized.  In the body of the email I have a series of RST recordsets to insert the story headlines by category.

Each category is defined by its own query & the RST loops get compiled at the end of the code. This all works fine, but what I would like to do is this ...

If a category contains no story then I want that part of the string to be null.  So in the example below I have inserted where I would like the if statement to run


' .....................................................................................................

' RST Insurance
Dim rstInsurance As Recordset
    
    Set rstInsurance = CurrentDb.OpenRecordset("Newsletter FS Sub Insurance")
    Do While Not rstInsurance.EOF
   


EmailBodyHeadlinesInsurance = EmailBodyHeadlinesInsurance & "<li>" & rstInsurance!title & "</li>"
 rstInsurance.MoveNext
    Loop
    rstInsurance.Close


' ... insert here something that states if record set is empty then EmailBodyHeadlinesInsurance = "" else EmailBodyHeadlinesInsurance  = "INSURANCE <br>" &  EmailBodyHeadlinesInsurance  

Open in new window


Can anybody help?
correlateAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Barry CunneyCommented:
' .....................................................................................................

' RST Insurance
Dim rstInsurance As Recordset
Dim intRecordCount%

intRecordCount% = 0
   
    Set rstInsurance = CurrentDb.OpenRecordset("Newsletter FS Sub Insurance")
    Do While Not rstInsurance.EOF

        intRecordCount% = intRecordCount% + 1

            EmailBodyHeadlinesInsurance = EmailBodyHeadlinesInsurance & "<li>" & rstInsurance!title & "</li>"
             
      rstInsurance.MoveNext
    Loop
   
rstInsurance.Close


' ... insert here something that states if record set is empty then EmailBodyHeadlinesInsurance = "" else EmailBodyHeadlinesInsurance  = "INSURANCE <br>" &  EmailBodyHeadlinesInsurance  

If intRecordCount% = 0 Then
 
      EmailBodyHeadlinesInsurance = "" 

else

      EmailBodyHeadlinesInsurance  = "INSURANCE <br>" &  EmailBodyHeadlinesInsurance

End If
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
correlateAuthor Commented:
Perfect - works a treat thank you very much
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.