469,625 Members | 1,911 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,625 developers. It's quick & easy.

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
Nov 13 '05 #1
3 1389
Phil wrote:
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.


Quick and dirty...
(air code)

Sub Form_BeforeInsert(Cancel As Integer)
With Me.RecordsetClone
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.
\__\

Nov 13 '05 #2
Phil wrote:
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.


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.
\__\

Nov 13 '05 #3
Phil wrote:
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


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.Recordsetclone
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.
Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by CSDunn | last post: by
3 posts views Thread by ruca | last post: by
3 posts views Thread by ken | last post: by
21 posts views Thread by planetthoughtful | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.