Page 2 of 2 FirstFirst 12
Results 16 to 24 of 24
  1. #16
    Buster55 is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Dec 2015
    Posts
    20

    Code:
    Here is the new code and still I get each new record showing victim Number as 1.
    
    Private Sub cmdAddNewVictim_Click()
    'When the user clicks on the command button it will copy and paste the highlighted record
     'Assign field values to be carried forward to variables
         MyField_1 = Me.txtCASE_NUMBER
    
     'Go to a new record
         DoCmd.GoToRecord , , acNewRec
     'Plug in old values from variables to new record
         Me.txtCASE_NUMBER = MyField_1
         
     'Count the number of victims assigned to this case number and assign the next the next numerical number to this victim
         
        [VICTIM_NO] = Nz(DMax("[VICTIM_NO]", "[Tbl_UCR_Victim]", "CASE_NUMBER=" & [Forms]![Frm_UCR_Victim]![txtCASE_NUMBER]), 0) + 1
         
     End Sub

  2. #17
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,369
    Then your expression must always be returning null, which is coerced to zero, upon which 1 is added. To test, put a break point on the gotorecord line and when you click the button, it will stop there. Then in the immediate window, type in a question mark and paste this part of your expression and hit return to see what the value is.
    DMax("[VICTIM_NO]", "[Tbl_UCR_Victim]", "CASE_NUMBER=" & [Forms]![Frm_UCR_Victim]![txtCASE_NUMBER])

    I suspect the result will be Null because I seem to recall from your first post that your victim number was text; if so, you are trying to add a number to a string.
    Last edited by Micron; 01-25-2016 at 09:32 AM. Reason: clarified 'immediate window'
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #18
    Buster55 is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Dec 2015
    Posts
    20
    I'm sorry to bother you yet Paul but try as I may, I can't get it to work.
    I even tried making a query to count the records that match the case number on the loaded form record.
    That works as long as I close the form and reopen it to that record before running the query.
    I tried refresh, requery, and even save but only by closing and reopening.
    I decided I would have to live with that.
    When I enter control value = that query comes up as a data type mismatch.
    I ten double check the table field and it is set to number.
    I figure the number field should accept the result of a count as that should be a number.
    You are right in that the database that these tables were originally in, had the victim number as text.
    I had changed that.
    I even deleted the control on the form and added a new one in case the old control was still using the text data type.
    Still the same result.
    I then inserted a new field in the table, copied all of the existing data to the new field, deleted the old field and renamed the new field to the old field name.
    Still the same result. (Type mismatch) using the query on the control.
    It make absolutely no sense to me.
    I have stripped all of the confidential data from the database and have uploaded it to bimcomputers.com/downloads/UCR_Test.zip
    I certainly don't blame you if you are tired of working with this and I do appreciate all of your help.

  4. #19
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Link doesn't work for me. You should be able to attach the file here after a compact/repair and zipping.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #20
    Buster55 is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Dec 2015
    Posts
    20
    UCR_Okeene.zip

    OK Paul. I tried to attach earlier but the database was still too large even after compact repair and zip. I just made a new database importing only the 2 tables and 2 forms that we should be concerned with. Now it is small enough. When I told it to attach I just got the above tags, I hope that will do it for you.
    And again thank you so much. I think our police department has given up on me doing this for them because I am just not bright enough.

  6. #21
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Won't pretend to follow what's going on in the app, but this appears to work (your case number field is text):

    [txtVICTIM_NO] = Nz(DMax("[VICTIM_NO]", "[Tbl_UCR_Victim]", "CASE_NUMBER='" & [Forms]![Frm_UCR_Victim]![txtCASE_NUMBER] & "'"), 0) + 1
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #22
    Buster55 is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Dec 2015
    Posts
    20
    Hallelujah!! YOU ARE THE MAN PAUL!!! I laid several of the codes by one another so I could try to figure out what I was missing and just decided I'm too old and not smart enough. I should be able to use that same code for all of the 7 other things I have to put in and count the same way though. I did have a problem with the first record being 0 instead of 1. I tried changing the 0 to 1 for the Nz but that didn't work so I just put the 1 in as the default property on the control and all is working great now.


  8. #23
    Buster55 is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Dec 2015
    Posts
    20
    I can't thank you enough for all of your help on this and I am so sorry that I was so ignorant about it. You were right and the CASE_NUMBER is a text file as it conforms to their formatting that they wanted with the yyyy-m-d-case number for that date format. I didn't realize that would be an issue since all we were doing was counting all of the victims entered who were assigned to that case number.

  9. #24
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 2
    Last Post: 12-22-2015, 09:09 PM
  2. Replies: 6
    Last Post: 01-12-2015, 05:22 PM
  3. Record Count based on Form control value
    By Monterey_Manzer in forum Forms
    Replies: 7
    Last Post: 11-29-2012, 10:47 AM
  4. COUNT Group Count Records COUNT FUNCTION
    By PMCOFFEY in forum Access
    Replies: 9
    Last Post: 11-09-2012, 09:40 PM
  5. export Excel control row count
    By TheShabz in forum Code Repository
    Replies: 1
    Last Post: 04-17-2010, 12:00 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