Results 1 to 9 of 9
  1. #1
    jpkeller55 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    169

    Sequential number on subform

    Hi,

    I have a form and subform that links two tables tblPatients and tblBleedDetails respectively. PK-FK is PatientID. There is a one to many relationship between the tblPatients and tblBleedDetails. I am logging patient bleed events for each patient sequentially so that the first event is 1, second event 2 and so on. How do I get the sequence number for each bleed event to start at 1 and increment by one each time a new event is entered on the subform?



    For example PatientID 12345 may have records in the tblBleedDetails with a sequence 1,2,3 for his three events and PatientID 23456 may have three events also sequenced 1,2,3.

    Thanks for any help or pointing me in the right direction.

  2. #2
    jpkeller55 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    169
    As I think about this some more, maybe I can use the DCOUNT function to see how many records exist for a particular PatientID, if any, and then add 1 to whatever value DCOUNT returns and use that as my sequence number. Does this make sense?

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Have you already reviewed this thread? https://www.accessforums.net/forms/n...orm-12001.html

  4. #4
    jpkeller55 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    169
    OK, I looked at the example from the thread you suggested and it indeed numbers rows accordingly on a form if you add a text box. I would like to be able to save this information in a table so that the sequence number becomes a record and not just a row number on a form. Does this make sense? So as I add a new bleed event on the subform, a new bleed event number is assigned and stored in the tblBleedDetails table with the sequence starting at 1 and incrementing by 1 for each individual PatientID.

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Maybe you will find this link helpful: http://www.baldyweb.com/CustomAutonumber.htm

  6. #6
    jpkeller55 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    169
    OK, I solved what I need to do using the following code in the subform before update event:
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
        Dim intHolder As Integer
     
        intHolder = DCount("BleedID", "qryBleedDetails", "PatientID =" & Me.PatientID)
        Me.PatientBleedSequence = intHolder + 1
    End Sub
    Thanks RG for taking a look...I appreciate your help.

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Excellent solution! Thanks for post back.

  8. #8
    jpkeller55 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    169
    Just as a follow-up, I moved this code to the Before Insert event of the form so that it would not update the sequence number if I modified any data on the form.

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Good point. You could also have simply checked to make sure it did not have one already in the BeforeUpdate event. Lots of ways to skin this cat here.

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

Similar Threads

  1. Adding record with next sequential number
    By stanley721 in forum Forms
    Replies: 3
    Last Post: 02-28-2011, 01:26 PM
  2. Help with Sequential Numbering
    By orion in forum Programming
    Replies: 3
    Last Post: 07-06-2009, 01:41 PM
  3. Assign A Sequential Number To A Table Row
    By KramerJ in forum Programming
    Replies: 11
    Last Post: 04-08-2009, 08:48 AM
  4. Replies: 1
    Last Post: 01-31-2009, 10:43 AM
  5. create sequential id
    By proudestmnky1 in forum Programming
    Replies: 0
    Last Post: 12-16-2008, 12:10 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