Results 1 to 3 of 3
  1. #1
    Buster55 is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Dec 2015
    Posts
    20

    Trying to Count records in a table matching a textbox on a form and insert that result in a textbox

    I have created quite a few databases using access but I am in no way proficient. What I have is a database for a Police dept. They want their case numbers automatically input using a yyyy-m-d-1 format. The result would be the first case number for today would be 2015-12-22-1. The last number represents how many incident reports have been filed on that date. So the next would be 2015-12-22-2. I have been able to get the date part by having a [txtRPTDATE] control and using datepart with "-" separators. The problem I am having is I am trying to count the previous records in the table with the same date (including the new one) and get that in a textbox control so I can refer to that textbox with my code for the[ txtCASE_ID] last digit. I have a totals query made that counts the records properly. I just can't seem to find anyway to get the result of the query to appear in the textbox on the form. I also tried using the dcount function in the textbox (which I had never done before) to no avail. Any help would be appreciated. I have been 2 days on this one problem that I am sure is a simple problem but apparently not for me. I am using access 2003 to build the database but will then be converting it to access 2007.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Post your attempted code for analysis.

    Use domain aggregate function: DLookup() or DCount().

    =DCount("*", "tablename", "[datefield]=#" & [datefield] & "#")

    or

    =DLookup("fieldname", "queryname", "where clause if needed")

    Custom unique identifier is a common topic. Start with https://www.accessforums.net/forms/a...ing-23329.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.

  3. #3
    Buster55 is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Dec 2015
    Posts
    20
    here is the code that the officer will click on to submit a new report.

    'Close the UCR main page form
    DoCmd.Close acForm, "Frm_UCR_MainPage", acSaveYes
    'Append the logged on officer information to a a new record
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "Qry_UCR_New_AppendOfficer"
    DoCmd.SetWarnings True
    'Open the form and go to the new record
    DoCmd.OpenForm "Frm_UCR_AdminReport"
    DoCmd.GoToRecord , , acLast
    DoCmd.Close acForm, "Frm_UCR_AdminReport", acSaveYes
    DoCmd.OpenForm "Frm_UCR_AdminReport"
    DoCmd.GoToRecord , , acLast
    'Create a case number for the new report.
    Forms!Frm_UCR_AdminReport.txtCASE_NUMBER.Value = Forms!Frm_UCR_AdminReport.txtRptYear & "-" & Forms!Frm_UCR_AdminReport.txtRptMonth & "-" & Forms!Frm_UCR_AdminReport.txtRptDay

    After that I am at the new record with the RPT_DATE saved in the table.
    RPT_DATE is set as Date-time in the table.

    I tried your code in the textbox

    =DCount("*","Tbl_UniformIncidentOffense","[RPT_DATE]=#" & [txtRPT_DATE] & "#")

    It worked like a charm.
    Thank you so very much.
    Now I just have to go in and clean up all of the junk code and querys that I put in it trying to make it work.
    I think the trick was the # since it was date that I wasn't using.

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

Similar Threads

  1. Replies: 3
    Last Post: 08-21-2015, 12:06 PM
  2. Replies: 5
    Last Post: 04-30-2015, 01:50 AM
  3. Enter query result in a form textbox
    By Damo10 in forum Forms
    Replies: 2
    Last Post: 06-30-2013, 06:43 PM
  4. Replies: 3
    Last Post: 08-03-2012, 02:37 AM
  5. Replies: 2
    Last Post: 02-04-2012, 01:48 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