Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8349761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:06:29+00:00 2026-06-09T08:06:29+00:00

Me again. This code works fine when only 1 item is selected, however when

  • 0

Me again. This code works fine when only 1 item is selected, however when more than one item is selected I get the error “syntax error (comma) in query expression” on the following line of code:
intCountNull = DCount(“*”, “Scrubbed”, strCriteria & ” Is Null”)

Here is my code:

Private Sub Command29_Click()
Dim strCriteria As String
Dim intCountNull As Integer
Dim varItem As Variant

'On Error GoTo Err_Command29_Click

Me.Fields_Values.RowSource = ""

For Each varItem In Me!List101.ItemsSelected
strCriteria = strCriteria & "," & Me!List101.ItemData(varItem)
Next varItem

strCriteria = Right(strCriteria, Len(strCriteria) - 1)

intCountNull = DCount("*", "Scrubbed", strCriteria & " Is Null")
Fields_Values.RowSource = intCountNull & " null values found in " & strCriteria

Exit_Command29_Click:
    Exit Sub
'Err_Command29_Click:
    'MsgBox "Please select a field"

End Sub

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:06:31+00:00Added an answer on June 9, 2026 at 8:06 am

    … when more than one item is selected I get the error “syntax error (comma) in query expression” on the following line of code: intCountNull = DCount("*", "Scrubbed", strCriteria & " Is Null")

    That makes sense. If the list box selections were “field1”, “field3”, and “field4”, your DCount() would throw error #3075, “Syntax error (comma) in query expression ‘field1,field3,field4 Is Null’.“

    The DCount() expression would be evaluated like this SELECT statement:

    SELECT Count(*)
    FROM Scrubbed
    WHERE field1,field3,field4 Is Null
    

    And the db engine will definitely complain about that WHERE clause. You can’t give it a list of field names and ask it whether the list Is Null. You would have to separately ask whether each field Is Null.

    That is the explanation for why you get that error. However, I think you need to change your approach.

    Build up the RowSource value list string for Fields_Values as you iterate through List101 selected items. (Make sure you have Value List as the Row Source Type property for Fields_Values.) Here is a tested sample which does what I think you want.

    Private Sub Command29_Click()
        Dim strCriteria As String
        Dim intCountNull As Integer
        Dim varItem As Variant
        Dim strRowSource As String
    
        Me.Fields_Values.RowSource = ""
        For Each varItem In Me!List101.ItemsSelected
            strCriteria = "[" & Me!List101.ItemData(varItem) & _
                "] Is Null"
            intCountNull = DCount("*", "Scrubbed", strCriteria)
            'Debug.Print strCriteria, intCountNull '
            strRowSource = strRowSource & ";" & intCountNull & _
                " null values found in " & _
                Me!List101.ItemData(varItem)
        Next varItem
    
        'Debug.Print strRowSource '
        If Len(strRowSource) > 0 Then
            strRowSource = Mid(strRowSource, 2)
            Me.Fields_Values.RowSource = strRowSource
        End If
        'Debug.Print strRowSource '
    End Sub
    

    Also I don’t see why the user should even be allowed to click Command29 unless List101 contains selected items. So consider disabling Command29 until selections have been made.

    Private Sub Form_Load()
        Me.Command29.Enabled = False
    End Sub
    
    Private Sub List101_AfterUpdate()
        Me.Command29.Enabled = (Me.List101.ItemsSelected.Count > 0)
    End Sub
    

    Finally, I’ll suggest you do yourself a favor by giving your controls meaningful names … Command29 could be cmdShowNullCounts and List101 could be lstFieldNames. Meaningful names are especially helpful when you’re dealing with dozens of controls. You should also find them helpful when you need to revisit the form design after a few months. Anyone else who has to take over in the future will appreciate your courtesy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to create and submit form within a javascript call. This code works fine
this code works completely fine in my pc while i compile it with codeblocks
Sorry to bother again, but I really need help transforming this Python2 code into
Sorry for asking this again but ppl seem to connect csrf only with form
Why the same question again This question has been asked around 100 times on
its me again with this project. im having a problem reading the text on
I need a form width a checkbox Don't show this again for my winform,
This figure again shows that every object has a prototype. Constructor function Foo also
I have this problem again and again... and still have not a satisfactory answer...
I'm facing this problem again and again, but can't find any solution (except mine,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.