473,786 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
8233
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 answer for this. I have a subform which the user selects an item description from a combo box from a table. I want to obtain the cost for the item (another field in the table) also. I've been able to produce the second data field by rewriting the...
2
2123
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 value in a field called 'Grade' that is also in the subform. The name of the main form is 'frmSelectByTest'. The 'SourceObject' of the subform and the subform name are the same. 'Grade' in the subform can be different for each student record...
3
1340
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 JScript? --
3
2007
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 long as I don't close the form. Once I close it the new defalut value does not get saved. Is there any way I could save it to the properties of the combo box? Thanks, Using A2k.
21
8778
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 like to include the ability to edit an existing value (drawn from an SQLite table) using a DOS console Python app, but my gut
2
3282
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 populated OK, but when I try to create a new record with a Microsoft datagridview control, I notice that the datecreated value does not get created. It looks as if the datagridview insert statements overrides the default value and prevent the default...
9
5052
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 Set(ByVal Value As Image)
2
11227
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 generated' So i have tried to do this: (getDate())+'System generated' (getdate()).'System generated' but neither seem to work
5
6265
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 would like. There was originally no default value and now I would like t he default value to be 12. The data type is number, long integer. The field display control is a combo box, the row source type is Table/Query and the row source is another...
0
9491
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10357
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10163
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4063
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.