473,396 Members | 1,966 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,396 software developers and data experts.

Copy from "field2" to new record "field1"

ryno du preez
Hello Let me start of to says I'm a complete newbie when It comes to VBA, But in the problem facing me I can't get around it in Access 2010.Please Help.

In my "Table1" there is two fields "Open" and "Close",
The data that is in the "Close" field must automaticly be copied to the "Open" field on a new Record(all in the same Table) The tables are linked via the same ID key

Id | Open | Close
1 | 100 | 150
1 | 150 | 275
1 | 275 |

I've tried to look at the code of the build in function in access to duplicate a record but know luck.
PLEASE HELP .....
Jul 5 '11 #1
12 3521
Rabbit
12,516 Expert Mod 8TB
You can use the Max(Close) to populate the new Open.
Jul 5 '11 #2
Thank you for your reply, I've tryed to use it in a query but keeps on giving me errors,the query I tryed to use was a update query. please bear in mind my VBA is very weak and close to none exsisting.
Jul 6 '11 #3
Jerry Maiapu
259 100+
First of all. Do you, want to insert values into open field from close field in a one-go process by say clicking a button or is it going to be an ongoing event ie every time you enter a value in close field you want a copy to be placed in the open field?

I think the simplest way to do this is to use append query to get values from close and add/insert into open column.

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO table1 ( [Open] )
  2. SELECT Close
  3. FROM table1;
I'm just wondering why on earth you could want to duplicate field values. You could use query to filter and retreive records for reporting and viewing from one column. Only if you expalin what you're trying to achieve, we can't solve the real mysery.
Jul 7 '11 #4
Jerry thank you for the reply. The reason I want to do this is to try and cancel out Human error .Because there is calculations being done between the open and close fieldies ([close]-[open]).
The last [close] entry is also automatically the next [open] value in a new record. and then waits for the user to enter the next [close] value to do the calculations.I'm adding the db in this post, the table in question is "TBrandstof" and the open [OpenOdometerL] and the close is [ClsOdometer], Your query runs correctly but I only want to update the last entry in close to the new records open
Attached Files
File Type: zip Brandstof.zip (208.7 KB, 125 views)
Jul 7 '11 #5
The input form is Feul from the main menu or FBrandstof
Thanks again for your help.
Jul 7 '11 #6
Jerry Maiapu
259 100+
I am using Ms access 2007. For some reason I cannot open your table make sure your mdb file is compitable with ms access 2007
Jul 8 '11 #7
nbiswas
149 100+
I have created a table as under

Expand|Select|Wrap|Line Numbers
  1. Field   DataType
  2. ------  --------
  3. RowID (AutoIncrement)
  4. ID     Number
  5. Open   Number
  6. Close  Number
Based on this , the below query should work

Expand|Select|Wrap|Line Numbers
  1. Insert into Table1(ID,Open)
  2. Select  Table1.[ID], Table1.[Close]
  3. FROM Table1
  4. where  Table1.[RowID] =  ( Select Count(*) from Table1);
Jul 8 '11 #8
NeoPa
32,556 Expert Mod 16PB
When you open the form set the .DefaultValue property of the txtOpen control to the maximum value found in the table so far. You can use :
Expand|Select|Wrap|Line Numbers
  1. Me.txtOpen.DefaultValue = Nz(DMax("[Close]","[Table1]"), 0)
You should also update this whenever you add a new record into the table. You can do this in the form's AfterUpdate event procedure :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_AfterUpdate()
  2.     If Me.NewRecord Then Me.txtOpen.DefaultValue = .txtClose
  3. End Sub
Jul 8 '11 #9
Here is a 2007 version .................................................. .
Attached Files
File Type: zip Database2.zip (87.4 KB, 135 views)
Jul 8 '11 #10
It works great thanks "nbiswas" only one little bug still to kill, The [ID] is a linked [ID] from another table "[REGNO]", If I run the query on the table only it updates perfectly but as soon as I try to run it from the joint form it doesn't update the Table content.
Do you have any ideas on how to fix the problem?
Thank you every one for each reply so far.
Jul 8 '11 #11
Jerry Maiapu
259 100+
I haven’t actually looked at your db but a SQL need to know on what date the close field value was closed. In that way we could kindly ask the SQL to sort the values by the dates in the close field in an Ascending order, and simply pick the recent closed value from the list. So obviously, the last value in the list will be the most recent/current record value in the closed field. So I am presuming you have a field called ClosedDate or something in the same table.
Try this:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO TBrandstof ([OpenOdometerL])
  2. SELECT Last([ClsOdometer] AS [lastvalue]
  3. FROM TBrandstof
  4. ORDER BY Last(ClosedDate);
Save the query as insertclosedvalues

You can manually run the above query or if you wish to automate using cmd button, then create a button on the form and use its on_click event to execute the above query.

Expand|Select|Wrap|Line Numbers
  1. DoCmd.SetWarnings False ‘Removes the default warning message of the query
  2. DoCmd.OpenQuery " insertclosedvalues ", acViewNormal
Jul 11 '11 #12
Jerry Maiapu
259 100+
For the linkage to work you should have two keys ( PK and FK) The FK field is the one need to be updated. so:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO TBrandstof ([OpenOdometerL,FK)
  2. SELECT Last([ClsOdometer]) AS [lastvalue], Last([FK]) AS LFK
  3. FROM TBrandstof
  4. ORDER BY Last(ClosedDate);
Replace FK with your FK field name.

PK= Primary Key
FK= Foreign key (one coming from the other table)
Jul 11 '11 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Dave Smithz | last post by:
Having adopted someone else's PHP cope and completing a crash course in the language I came across a (probably common) problem with the current code. On a registration form, whenever users names...
1
by: Simon Wigzell | last post by:
Is it possible to retrieve data with ASP sorted on 2 fields? I've tried : SELECT * FROM ORDER By Field1 AND Field 2 But it gives an error. I've searched the internet on this topic to no avail....
6
by: Matthew Louden | last post by:
The following ASP code yields the following error, but actually the new record is stored in database. The same error happens when the application deletes a record, such as sqlStmt ="delete from...
5
by: Chad Richardson | last post by:
Is there a way in SQL Server 2000 to extract data from a table, such that the result is a text file in the format of "Insert Into..." statements, i.e. if the table has 5 rows, the result would be 5...
2
by: CFW | last post by:
I use the following flawlessly to insert a single field: strSQL = "Insert into (Casket) Values " _ & "(" & conQuote & NewCasket & conQuote & ")" Set db = CurrentDb If MsgBox(NewCasket & " is...
3
by: Leo Nunez | last post by:
Hello! I need copy from structure "A" to "B" that contains "strings" in a one line code. Me problem like this : typedef struct tHeader{ char field1; char field2; char field3;
175
by: Ken Brady | last post by:
I'm on a team building some class libraries to be used by many other projects. Some members of our team insist that "All public methods should be virtual" just in case "anything needs to be...
1
by: dtdev | last post by:
hi, i have a: char record = new char; In this i am loading a fixedlength record from a file. What i would like to do, is to copy segments from this array into either smaller strings or ...
7
by: Brave | last post by:
I am hoping for a code example of how to do this, and hopefully it will help me to see an easy way to code what seems to be a huge monster. I need to create a form that has two pulldown menues...
1
by: sql2020 | last post by:
Hi, i am fresh grad and having some problems. the problems as below and iIt is quiet urgent......... i have two CheckedListBox (CLBa and CLBb) , and i want the user selected CheckedListBox is...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.