Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369

    Unanswered: [prev]: a field value in the previous record as default value?

    Hi, in a history table, (also for use in some queries, might be a different issue/code though?), I want to set the default value for a field in a new record to the value of a DIFFERENT field in the previoius record. I particularly want to populate one table that have the fields previous_value and new_value. The former should be set to copy the value of the latter in the previous record. That way I do not have to deal with that field in forms etc.

    I know that there is a possibility to use [prev] in some way, but how to do it in this context when I want to set it as the default value for the table field itself?

  2. #2
    Join Date
    Jun 2002
    Location
    Mpls/St.Paul area
    Posts
    303
    If this occurs in a form, perhaps you could use the OnCurrent event of the form properties to run the following.


    OnCurrent...
    1) get the ID of the current record
    2) if the user is not on the first record.
    3) set text box in question to the lookup value of the field from the previous record.

    Something like this...
    Dim myInt as Integer

    myInt = me.myIDfield      &n bsp; 'the ID of the current record
    if myInt <> 1 then&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;'when you are not on the first record...
    &nbsp;&nbsp;&nbsp;&nbsp;me.myField = dlookup("[myOtherFieldName]","myDatasource","[myIDfield]=" & myInt - 1)
    end if

    Check out the three parameters of DLookup in Access Help.
    John
    This is the day the Lord has made, I will rejoice and be glad in it.

  3. #3
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369
    Originally posted by jpshay
    If this occurs in a form,
    The table that I want updated is a history table, that will not be present / open - I only want to add data to it, so a form function is not what I am looking for here, but thanks for the example, might be useful in other contexts :-)

  4. #4
    Join Date
    Jun 2002
    Location
    Mpls/St.Paul area
    Posts
    303
    Is there code or some event that triggers the writting of an entry to this history table?

    If so, perhaps you could key off of that and use the dlookup in conjunction with an insert or update SQL command.
    John
    This is the day the Lord has made, I will rejoice and be glad in it.

Posting Permissions

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