473,385 Members | 1,325 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 1536
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Terry Bickle | last post by:
Please forgive me for using the wrong term here or there. I'm an old Excel 4 macro guy who didn't convert to VB and I'm tinkering with an Access 2000 DB. I'm sure there is a simple Access 101...
2
by: CSDunn | last post by:
Hello, I have a field called 'TestGrade'in a subform called 'frmSelectByTestSub'that I need to assign a default value to, and the value needs to be an integer value that is exactly the same as the...
3
by: ruca | last post by:
Hi, How can I set a parameter of a function optinal and have a default value? In VB I do like this: Function myFunction (Optional ByVal bExist as Boolean = False) What's the equivalent in...
3
by: ken | last post by:
Hi, I want to reset the default value of a combo box everytime someone selects something from its list. I have in the after update event combo.defaultvalue = combo.value. Anyhow this works, as...
21
by: planetthoughtful | last post by:
Hi All, As always, my posts come with a 'Warning: Newbie lies ahead!' disclaimer... I'm wondering if it's possible, using raw_input(), to provide a 'default' value with the prompt? I would...
2
by: Bob | last post by:
I have a CreatedOn field , datetime, which has GetDate() as the default value in SQL server 2000 table. When I create a new record in the table itself in enterprise manager, the field gets...
9
by: Eric | last post by:
Hi Everyone, I'm writing a UserControl that exposes a property of the type System.Drawing.Image, like this: Public Property DefaultImage() As Image Get Return propDefaultImage End Get...
2
by: tezza98 | last post by:
Help please, Im using SQL server Management Studio Express and i want to change the default value of a varchar(50) column. i want the defaultdate to be like this '5/04/2007 11:15 pm System...
5
by: sillyr | last post by:
Hi- I'm using Access 2007. I wanted to change a default value for a field that previously had no default value. I though it would be easy- just set the default value setting to the number t hat I...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.