Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2011
    Posts
    5

    Unanswered: Use of =DCount() in form field produces error.

    Hi All

    I'm a bit of a newbie to Access and this forum, I have tinkered over the years, but have never used Access in a big way.

    I'm looking at using Access as a database of telephone extensions as my Excel spreadsheet is now 30MB.

    I'm using Access 2010

    I have a table of 8000+ numbers in the format 2BBBNNN

    I want to count the number of entries starting 2313, so in a field on the form I have entered the following in the control source:

    =DCount("*","[Report_list_station]","[Station_Config] Like '2313*'")

    But all I receive is #Error "424 Object required"

    I have tried various syntax, but I just can't get it to work.
    Table=Report_list_station
    Field=Station_Config

    Using Like as the criteria in a query works, so I don't think it is anything to do with the fields type.

    I would be most grateful if someone could point me in the right direction.

    Regards

    Ian

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    1. Remove the square brackets:
    Code:
    =DCount("*","Report_list_station","Station_Config Like '2313*'")
    2. Check (if it's not already done) that "Station_Config" is defined as being of type Text. If it's numeric, you need to convert it to string:
    Code:
    DCount("*", "Report_list_station", "CStr(Station_Config) Like '2313*'")
    Have a nice day!

  3. #3
    Join Date
    Nov 2011
    Posts
    5
    Quote Originally Posted by Sinndho View Post
    1. Remove the square brackets:
    Code:
    =DCount("*","Report_list_station","Station_Config Like '2313*'")
    2. Check (if it's not already done) that "Station_Config" is defined as being of type Text. If it's numeric, you need to convert it to string:
    Code:
    DCount("*", "Report_list_station", "CStr(Station_Config) Like '2313*'")
    Thank you, that worked a treat.
    I originally did not have the quotes in and Access automatically included the square brackets.
    I looked at some example code and later added the quotes, but did not remove the square brackets

    I also thought I would take it one stage further and try =DCount("*","Report_list_station","Station_Config Like '23' & cmbBusUnit.column(1) & '*'")

    where cmbBusUnit is a combo box.

    But this also gives an #Error

    Another text box has in it =[cmbBusUnit].column(1) and this works, giving a result of 13 or 23 the two values I have in my combo.

    So I tried

    =DCount("*","Report_list_station","Station_Config Like '23' & [cmbBusUnit].column(1) & '*'")

    and

    =DCount("*","Report_list_station","Station_Config Like '23' & 'cmbBusUnit'.column(1) & '*'")

    and

    =DCount("*","Report_list_station","Station_Config Like '23' & Me.<cmbBusUnit>.column(1) & '*'")

    But all these also give a #Error

    Thanks for your support.

    Ian

  4. #4
    Join Date
    Nov 2011
    Posts
    5
    Quote Originally Posted by imellor View Post
    Thank you, that worked a treat.
    I originally did not have the quotes in and Access automatically included the square brackets.
    I looked at some example code and later added the quotes, but did not remove the square brackets

    I also thought I would take it one stage further and try =DCount("*","Report_list_station","Station_Config Like '23' & cmbBusUnit.column(1) & '*'")

    where cmbBusUnit is a combo box.

    But this also gives an #Error

    Another text box has in it =[cmbBusUnit].column(1) and this works, giving a result of 13 or 23 the two values I have in my combo.

    So I tried

    =DCount("*","Report_list_station","Station_Config Like '23' & [cmbBusUnit].column(1) & '*'")

    and

    =DCount("*","Report_list_station","Station_Config Like '23' & 'cmbBusUnit'.column(1) & '*'")

    and

    =DCount("*","Report_list_station","Station_Config Like '23' & Me.<cmbBusUnit>.column(1) & '*'")

    But all these also give a #Error

    Thanks for your support.

    Ian
    I managed to get it working, after looking at various web sites, I used:
    =DCount("*","Report_list_station","[Station_Config] Like '23" & cmbBusUnit.column(0) & "*'")

    Thanks for you help

    Ian

  5. #5
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •