Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    luckydead is offline Novice
    Windows 10 Office 365
    Join Date
    Nov 2020
    Posts
    25

    Dcount additional criteria

    How can i manage the dcount to support the second criteria

    So i decide to do it like this:
    Code:
    Public Sub CheckTable(ByVal place As String)
    
    
    If DCount("*", place, " IsNull([ver1_2])=True") > 0 Then
         'table has empty ver1_2 records
         showme = 0
    Else
        'do something else - table doesn't have empty records
        showme = 1
    End If
    
    
    End Sub
    and here user will input manually the select number:
    Code:
    Sub InputBoxTest()
        inputData = InputBox("What is your select?", "Select ID")
        '
        ' Check to see if any data was entered
        '
        If inputData = "" Then
            '
            ' If so, display it
            '
            'MsgBox inputData
            MsgBox "Please enter some number"
        End If
    End Sub
    So my question is how i can add inside "If DCount("*", place, " IsNull([ver1_2])=True") > 0 Then" also to search where Select = inputdata



    So to become like this:
    - search select = inputdata , if its matching with Table data, then search if ver1_2 is null and if it has then do something else other.
    Click image for larger version. 

Name:	Capture2.PNG 
Views:	10 
Size:	13.4 KB 
ID:	45398

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    Use " AND Select = " & inputdata
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    luckydead is offline Novice
    Windows 10 Office 365
    Join Date
    Nov 2020
    Posts
    25
    yes i had already try something like that :
    Code:
    If DCount("*", place, "select" = "& inputData &" And " IsNull([ver1_2])=True") > 0 Then
    but its not working

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    NO, you combine the criteria, hence the AND?
    Not sure if Select is a reserved word as well, so enclose that with []
    Edit: just seen you put that at the front😔
    Put it all into a string so you can debug.print it, to see if correct.

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    Get rid of the last " before the isnull

  6. #6
    luckydead is offline Novice
    Windows 10 Office 365
    Join Date
    Nov 2020
    Posts
    25
    i do it like this now:
    Code:
    Public Sub CheckTable(ByVal place As String)
    
    
    If DCount("*", place, "[select]" = "& inputData & And  IsNull([ver1_2])=True") > 0 Then
         'table has empty ver1_2 records
         showme = 0
    Else
        'do something else - table doesn't have empty records
        showme = 1
    End If
    
    
    End Sub
    Seems to execute the code, but it gives back return 1 .. but select 3 have missing ver1_2 field.
    Click image for larger version. 

Name:	Capture5.PNG 
Views:	11 
Size:	15.0 KB 
ID:	45399

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    Is that null though or a zls?

  8. #8
    luckydead is offline Novice
    Windows 10 Office 365
    Join Date
    Nov 2020
    Posts
    25
    what do you mean zls?

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    Zero length string
    Does it work for select=1?

  10. #10
    luckydead is offline Novice
    Windows 10 Office 365
    Join Date
    Nov 2020
    Posts
    25
    its just empty textbox field

  11. #11
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    Empty is not null. Test that field to see what it actually is. Confusing I know

  12. #12
    luckydead is offline Novice
    Windows 10 Office 365
    Join Date
    Nov 2020
    Posts
    25
    so other option is to change in dcount not to be Null to be = "" ?

  13. #13
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  14. #14
    luckydead is offline Novice
    Windows 10 Office 365
    Join Date
    Nov 2020
    Posts
    25
    any ideas why it returns 0 always with this criterias ?
    Code:
    If DCount("*", place, "[select]" = "& inputData & And IsNull([ver1_2])=True") > 0 Then
    Seems like that it cant get correct information.
    Maybe other option to change dcount with other sql query code to get the information:
    Select ver1_2 From place Where select= inputdata ,something like that maybe ?

  15. #15
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    If DCount("*", place, "[select]" = "& inputData & And IsNull([ver1_2])=True") > 0 Then
    You need to look at variable isolation using SQL strings in VBA:
    https://docs.microsoft.com/en-us/off...s-and-controls
    Could you please try (examine the differences and have a look at the domain aggregate functions syntax)-https://www.datanumen.com/blogs/understand-domain-aggregate-functions-ms-access-explore-practical-applications/:
    Code:
    If DCount("*",place, "[select] = '"& inputData & "' And IsNull([ver1_2])=True") > 0 Then
    or as per your other post (https://www.accessforums.net/showthr...613#post477613) if the [select] field is numeric:

    Code:
    If DCount("*",place, "[select] = Cint("& inputData & ") And IsNull([ver1_2])=True") > 0 Then
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Disk space requirements of additional fields vs additional records
    By pharmacologist in forum Database Design
    Replies: 2
    Last Post: 03-17-2021, 09:23 PM
  2. dcount criteria
    By markjkubicki in forum Programming
    Replies: 2
    Last Post: 11-26-2018, 03:01 PM
  3. close form button with additional criteria
    By woodpecker in forum Access
    Replies: 5
    Last Post: 10-21-2017, 02:31 PM
  4. Inner join with additional criteria
    By cwillson in forum Queries
    Replies: 8
    Last Post: 09-13-2017, 01:00 AM
  5. RC Notation and additional criteria
    By mkc80 in forum Access
    Replies: 3
    Last Post: 11-05-2012, 03:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums