Default value help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phil

    Default value help

    Newbie to Access so am having a BIT of difficulty.

    I am trying to get a field value in a new record to equal the value of the
    same field of a previous one.

    For instance,
    Field1 + Field2 = Field3
    In the next record i want Field3 to have the default value of the previous
    Field3.

    Hope you can understand.

    Thanks


  • Trevor Best

    #2
    Re: Default value help

    Phil wrote:
    [color=blue]
    > Newbie to Access so am having a BIT of difficulty.
    >
    > I am trying to get a field value in a new record to equal the value of the
    > same field of a previous one.
    >
    > For instance,
    > Field1 + Field2 = Field3
    > In the next record i want Field3 to have the default value of the previous
    > Field3.[/color]

    Quick and dirty...
    (air code)

    Sub Form_BeforeInse rt(Cancel As Integer)
    With Me.RecordsetClo ne
    If .RecordCount Then
    .MoveLast
    Me!Field3 = !Field3
    End If
    End With
    End Sub

    Not sure about about using that with block, would feel more comfortable
    with a variable that I can close and set to nothing afterwards although
    ISTR reading in this group that the above is acceptable and that Access
    would clean up after itself (unlike my daughter :-)

    --

    \\\\\\
    \\ \\ Windows is searching
    \ \ For your sig.
    \ \ Please Wait.
    \__\

    Comment

    • Trevor Best

      #3
      Re: Default value help

      Phil wrote:
      [color=blue]
      > Newbie to Access so am having a BIT of difficulty.
      >
      > I am trying to get a field value in a new record to equal the value of the
      > same field of a previous one.
      >
      > For instance,
      > Field1 + Field2 = Field3
      > In the next record i want Field3 to have the default value of the previous
      > Field3.[/color]

      Oh, just remembered, Ctrl+@ will copy the previous record's field value
      into the current field (that's Ctrl+" for you septics:-)

      --

      \\\\\\
      \\ \\ Windows is searching
      \ \ For your sig.
      \ \ Please Wait.
      \__\

      Comment

      • Salad

        #4
        Re: Default value help

        Phil wrote:
        [color=blue]
        > Newbie to Access so am having a BIT of difficulty.
        >
        > I am trying to get a field value in a new record to equal the value of the
        > same field of a previous one.
        >
        > For instance,
        > Field1 + Field2 = Field3
        > In the next record i want Field3 to have the default value of the previous
        > Field3.
        >
        > Hope you can understand.
        >
        > Thanks
        >
        >[/color]

        Here is a function tha may work. I don't know if you store the values
        to Field3.

        Private Function Field3Default() As Long
        'not sure is your values are long, currency, your choice
        Dim rst As REcordset
        set rst = Me.Recordsetclo ne
        If rst.RecordCount > 0
        rst.moveLast
        Field3Default = rst!Field1 + rst!Field2
        Endif
        rst.close
        set rst = nothing
        End Function

        You can now put this code into the OnCurrent event. Ex:
        If Me.NewRecord Then
        Me.Field3 = Field3Default()
        Endif

        I really don't see why you don't make Field1/2 have the default values
        of the prior record and make Field3 a calc'd field since it is the
        addition of the 2 that make up the result. I suppose you have a reason.


        Comment

        Working...