Results 1 to 14 of 14
  1. #1
    civl_eng is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    41

    Dcount By Multiple Textbox

    hi guys, i want to use Dcount for count by multiple text box but when one textbox is null doesn't find any record, and i have to use alot of if and elseif for this purpose, for example i wrote Multiple elseif tow textbox :


    Click image for larger version. 

Name:	Dcount.png 
Views:	17 
Size:	4.4 KB 
ID:	34774

    If Not IsNull(Me.Text4) And Not IsNull(Me.Text6) Then


    x = DCount("ID", "tbl_Patients", "[P_Sex]= '" & Me.Text4 & "' and [P_Status]= '" & Me.Text6 & "'")


    ElseIf Not IsNull(Me.Text4) And IsNull(Me.Text6) Then


    x = DCount("ID", "tbl_Patients", "[P_Sex]= '" & Me.Text4 & "'")


    ElseIf IsNull(Me.Text4) And Not IsNull(Me.Text6) Then




    x = DCount("ID", "tbl_Patients", "[P_Status]= '" & Me.Text6 & "'")


    ElseIf IsNull(Me.Text4) And IsNull(Me.Text6) Then


    x = DCount("ID", "tbl_Patients")


    End If


    MsgBox x

    ,,,,,,,,,,
    for this problem i try to use Nz function for doesn't consider null textbox as below code :

    x = DCount("ID", "tbl_Patients", "[P_Sex]= '" & Nz(Me.Text4, "") & "' and [P_Status]= '" & Nz(Me.Text6, "") & "'")

    but it's not working again


    is there any better solution?? (i have to do this without querry)

    thanks in advanced and sorry for my poor english

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Maybe use LIKE and wildcard.

    x = DCount("ID", "tbl_Patients", "[P_Sex] LIKE '" & Nz(Me.Text4, "*") & "' AND [P_Status] LIKE '" & Nz(Me.Text6, "*") & "'")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    A shot in the dark:

    x = DCount("ID", "tbl_Patients", "[P_Sex] Like '" & Nz(Me.Text4, "*") & "' and [P_Status] Like '" & Nz(Me.Text6, "*") & "'")

    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Oops, sorry June. I guess great minds think alike...sometimes mine too.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    civl_eng is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    41
    hey,,,thank you so much june7 and pbaldy,
    Now i have another problem, i want to add tow Dates range for this code as same your code and if Text boxes of date are empty doesn't consider them in querry, i wrote this code for date querry : (Type of date is Text)

    Click image for larger version. 

Name:	DAte.png 
Views:	12 
Size:	3.0 KB 
ID:	34779

    x = DCount("ID", "tbl_Patients", "[P_Date] Between '" & Me.Text0 & "' And '" & Me.Text2 & "'")

    And i combined the code(tow dates) with th first code(gender,marital status)

    x = DCount("ID", "tbl_Patients", "[P_Sex] LIKE '" & Nz(Me.Text4, "*") & "' AND [P_Status] LIKE '" & Nz(Me.Text6, "*") & "' And [P_Date] Between '" & Me.Text0 & "' And '" & Me.Text2 & "'")

    Above code is working if all of the textbox is fill, but when textboxes of Date is empty doesn't find any record, is it possible to use Like,NZ in Textboxes of Date???

    Thanks again for the first help.
    Today, 06:19 AM
    pbaldy
    Today, 06:19 AM
    pbaldy

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The Nz() function, with dates before/after anything in your data.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Oh, and dates need # as a delimiter, not '.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    civl_eng is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    41
    can you give me the corrected of code ?? (type of date is Text)

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Like

    Nz(Me.Text0, #1/1/1980#)

    I would question the date field being text. You'll probably have wonky issues with it, can't do date math, etc.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    If date is stored in a text type field, code needs to convert to date type for the criteria to work. Try CDate() function.

    Why would date be in a text field?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    civl_eng is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    41
    hey, thank you all, sorry for the delay in replying.

    my date is persian date and access doesn't support it, and we have to use text type instead date fields.

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    What is Persian date - international structure? http://allenbrowne.com/ser-36.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  13. #13
    civl_eng is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    41
    can you add "Like" and "nz" for textboxes in this below code ????

    x = DCount("ID", "tbl_Patients", "[P_Date] Between '" & Me.Text0 & "' And '" & Me.Text2 & "'")

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    LIKE and wildcard is for text data not numbers. As already advised, dates as text will not work for chronological sequencing or calculating. True date values are actually numbers with a specific display format.

    When stored as text 3/25/2018 will not sort before 10/25/2018, however 03/25/2018 will because this is alpha sorting.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 05-22-2014, 05:58 AM
  2. Dcount using textbox with like
    By naeemahmad in forum Programming
    Replies: 7
    Last Post: 04-23-2014, 04:14 PM
  3. DCount with Multiple Criteria
    By Newbie11 in forum Reports
    Replies: 4
    Last Post: 05-25-2012, 09:04 AM
  4. How do you use DCOUNT for multiple criteria?
    By wwhit in forum Programming
    Replies: 5
    Last Post: 05-15-2012, 11:14 AM
  5. Replies: 0
    Last Post: 06-11-2009, 09:51 AM

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