Results 1 to 8 of 8
  1. #1
    dniezby is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2013
    Posts
    183

    Increment based on linked value

    I have a field that I want to increment. That's not the issue. A simple Dmax and it does the job. The issue comes up when I move to a new main form. It keeps going.



    Here is an example.

    The table I'm using had a field "event_id". Many records in this table will have that same event id. The field I want to increment will be "roundComplete"

    I can get it to put an incrementing field but if the event_id changes, I need that "roundComplete" to start at 1 again.

    Thoughts on how to do this?
    I could just enter them manually but I would prefer to have it so its automatic.

  2. #2
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    What code are you using now?

    It sounds like you might need a table.

    Dale

  3. #3
    dniezby is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2013
    Posts
    183
    Well, right now this is what I did.

    Code:
    ' check to see if current event_id is the ' same as the record I'm working with
    
    varA = DLookup("event_id","events","event_id=" & event_id)
    
    ' enter a increment value 
    If event_id = varA then
     roundComplete = Dmax("roundComplete","plr_transactions")+1
    This is working except I can't figure out how to have it restart with different event_ids

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Perhaps something like:
    Me.roundComplete = Nz(DMax("roundComplete", "yourTableName", "event_id=" & Me.event_id), 0) + 1
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    Code:
    if Dlookup("[event_id]","events","event_id=" & event_id") then
       Dmax("roundComplete",plr_transactions")+1)
    else
        roundComplete=1
    end if
    Air code.
    Should work.


    Dale

  6. #6
    dniezby is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2013
    Posts
    183
    Quote Originally Posted by Bob Fitz View Post
    Perhaps something like:
    Me.roundComplete = Nz(DMax("roundComplete", "yourTableName", "event_id=" & Me.event_id), 0) + 1
    Didn't even think to use the Nz function. Don't know if I understand why it works, but it does.


    Dale, I tried your code too and it did not work. Was giving me syntax errors. Thanks anyway though.

  7. #7
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    Glad you got it working.
    My air coding does need some more work.
    Like my air guitar.

    Dale

  8. #8
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by dniezby View Post
    Didn't even think to use the Nz function. Don't know if I understand why it works, but it does.
    dniezby
    Glad it worked for you. Perhaps some explanation would help your understanding.
    The DMax() function returns the maximum value in the field called "roundComplete" where the field called "event_id" in the table is = to the value of the control of the same name on the form. I didn't test to see what DMax() returns if no matching value is found. It may be that it would return 0 anyway but the Nz() function was included just in case. All we need then is to add one to the value with +1 at the end.

    Hope this helps.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

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

Similar Threads

  1. Replies: 8
    Last Post: 07-06-2013, 05:13 PM
  2. Replies: 13
    Last Post: 05-01-2013, 09:01 AM
  3. Replies: 1
    Last Post: 02-23-2012, 11:48 AM
  4. Replies: 5
    Last Post: 11-12-2010, 12:10 PM
  5. Replies: 3
    Last Post: 02-05-2010, 10: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