473,657 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Move record from one table to another

I am trying to move a record from one linked table to another within
access, but I'm a complete beginner to VBA and don't know exactly where
to begin.

I have an access file that has the two linked tables, which each link
to separate SQL databases using separate ODBC connections.

I have a form that has a view of table1 and a set of buttons for
manipulating the data in database1.

The tough part is the button that's going to go on this form which
moves the record that's currently being viewed into a new record in
table2 (database2).

Through extensive testing I thought I found it's impossible to simply
do this with the built-in form builder tools - it only works if one of
the tables are local and not linked. However, queries which manipulate
data between linked tables work fine, which is what gave me the notion
I could do this with a little VBA code and a couple custom queries.

So far, the plan is the make the button do this:
1) Set a "pushFlag" column in the record in table1 to a specific
identifying value ("1" for now)
2) Runs an insert query to insert "all records with pushFlag = 1"
into table2. (this would create a copy of the record)
3) Sets the "status" field in the new record in table2 to a specific
value. ("done" for now)
4) Runs a delete query that first checks for duplicates (records that
exist in both the table1 and table2) and if a duplicate is found the
table1 record is removed. If a duplicate is not found, then the insert
must have failed for some reason. Instead of deleting the record the
user is notified that the insert failed, probably because of mal-formed
data in the record.

Does this sound remotely feasible? Would anyone be willing to help me
get this to work?

Jul 26 '06 #1
9 24652
A better question is; Why? Why move a record from one table to
another? If you're trying to differentiate between one type of record
and another, why not just add a flag to the table?

What you're asking for is fairly easy to do, but moving records from
table to table isn't a very logical or stable way to track data.

I think rather than ask someone help you commit suicide, you should ask
someone for some guidance. Building a database isn't like building
with Legos, not everyone fully understands the concepts needed to build
a database properly. If they did, true DBAs wouldn't be making
$80K/yr.

Jo*********@gma il.com wrote:
I am trying to move a record from one linked table to another within
access, but I'm a complete beginner to VBA and don't know exactly where
to begin.

I have an access file that has the two linked tables, which each link
to separate SQL databases using separate ODBC connections.

I have a form that has a view of table1 and a set of buttons for
manipulating the data in database1.

The tough part is the button that's going to go on this form which
moves the record that's currently being viewed into a new record in
table2 (database2).

Through extensive testing I thought I found it's impossible to simply
do this with the built-in form builder tools - it only works if one of
the tables are local and not linked. However, queries which manipulate
data between linked tables work fine, which is what gave me the notion
I could do this with a little VBA code and a couple custom queries.

So far, the plan is the make the button do this:
1) Set a "pushFlag" column in the record in table1 to a specific
identifying value ("1" for now)
2) Runs an insert query to insert "all records with pushFlag = 1"
into table2. (this would create a copy of the record)
3) Sets the "status" field in the new record in table2 to a specific
value. ("done" for now)
4) Runs a delete query that first checks for duplicates (records that
exist in both the table1 and table2) and if a duplicate is found the
table1 record is removed. If a duplicate is not found, then the insert
must have failed for some reason. Instead of deleting the record the
user is notified that the insert failed, probably because of mal-formed
data in the record.

Does this sound remotely feasible? Would anyone be willing to help me
get this to work?
Jul 26 '06 #2
The two databases which are on different computers are already in
place.

It's not just a move from one table to another within the same
database, it's a move from one machine to another. Access is simply
the 'bridge' between these two databases.

It's a very complicated setup, but if this intermediate step is
relatively easy in Access then it would make our work here very easy.
ManningFan wrote:
A better question is; Why? Why move a record from one table to
another? If you're trying to differentiate between one type of record
and another, why not just add a flag to the table?

What you're asking for is fairly easy to do, but moving records from
table to table isn't a very logical or stable way to track data.

I think rather than ask someone help you commit suicide, you should ask
someone for some guidance. Building a database isn't like building
with Legos, not everyone fully understands the concepts needed to build
a database properly. If they did, true DBAs wouldn't be making
$80K/yr.
Jul 26 '06 #3
Dim rec, rec2 as recordset
Dim db As Database

Set db = CurrentDb
Set rec = db.OpenRecordse t("FirstTable ")
Set rec2 = db.OpenRecordse t("SecondTable" )

You can then check, add and edit data using the proper calls
i.e.

rec2.addnew
rec2("field1") = "Done"
rec2.update

You can probably set up a query in advance that finds dupes (there's a
wizard that will do this) and then open the query just like you opened
the tables above, and delete the records.
Joshua.B...@gma il.com wrote:
The two databases which are on different computers are already in
place.

It's not just a move from one table to another within the same
database, it's a move from one machine to another. Access is simply
the 'bridge' between these two databases.

It's a very complicated setup, but if this intermediate step is
relatively easy in Access then it would make our work here very easy.
ManningFan wrote:
A better question is; Why? Why move a record from one table to
another? If you're trying to differentiate between one type of record
and another, why not just add a flag to the table?

What you're asking for is fairly easy to do, but moving records from
table to table isn't a very logical or stable way to track data.

I think rather than ask someone help you commit suicide, you should ask
someone for some guidance. Building a database isn't like building
with Legos, not everyone fully understands the concepts needed to build
a database properly. If they did, true DBAs wouldn't be making
$80K/yr.
Jul 26 '06 #4
Thanks for the prompt response.

What exaclty in your code makes it so that it knows WHAT record it's
working on? I assume a record set is collection of records (like a
table), so how does access know I only want to move the record that's
currently being viewed? This is all in the context of the form viewing
table1, right?

Did you mean "Done" litterally?

ManningFan wrote:
Dim rec, rec2 as recordset
Dim db As Database

Set db = CurrentDb
Set rec = db.OpenRecordse t("FirstTable ")
Set rec2 = db.OpenRecordse t("SecondTable" )

You can then check, add and edit data using the proper calls
i.e.

rec2.addnew
rec2("field1") = "Done"
rec2.update

You can probably set up a query in advance that finds dupes (there's a
wizard that will do this) and then open the query just like you opened
the tables above, and delete the records.
Jul 26 '06 #5
This is a response to a very similar question...

http://groups.google.com/group/comp....cf92573e6b84f7

watch the wrap... and that should work for you.

You just specify the database you want to append to in the SQL
statement.

Jul 26 '06 #6
You would specify that in a WHERE clause. So the code would be
something like:
set rec = db.openrecordse t ("Select * from Table1 where ID = " &
me.TableID & "")

Whatever field you're keying off of would be in the WHERE clause.

Jo*********@gma il.com wrote:
Thanks for the prompt response.

What exaclty in your code makes it so that it knows WHAT record it's
working on? I assume a record set is collection of records (like a
table), so how does access know I only want to move the record that's
currently being viewed? This is all in the context of the form viewing
table1, right?

Did you mean "Done" litterally?

ManningFan wrote:
Dim rec, rec2 as recordset
Dim db As Database

Set db = CurrentDb
Set rec = db.OpenRecordse t("FirstTable ")
Set rec2 = db.OpenRecordse t("SecondTable" )

You can then check, add and edit data using the proper calls
i.e.

rec2.addnew
rec2("field1") = "Done"
rec2.update

You can probably set up a query in advance that finds dupes (there's a
wizard that will do this) and then open the query just like you opened
the tables above, and delete the records.
Jul 26 '06 #7
Jo*********@gma il.com wrote:
I am trying to move a record from one linked table to another within
access, but I'm a complete beginner to VBA and don't know exactly where
to begin.

I have an access file that has the two linked tables, which each link
to separate SQL databases using separate ODBC connections.

I have a form that has a view of table1 and a set of buttons for
manipulating the data in database1.

The tough part is the button that's going to go on this form which
moves the record that's currently being viewed into a new record in
table2 (database2).
You can do this.
Through extensive testing I thought I found it's impossible to simply
do this with the built-in form builder tools - it only works if one of
the tables are local and not linked. However, queries which manipulate
data between linked tables work fine, which is what gave me the notion
I could do this with a little VBA code and a couple custom queries.

So far, the plan is the make the button do this:
1) Set a "pushFlag" column in the record in table1 to a specific
identifying value ("1" for now)
This is all untested. In the button click event try the following:

CurrentDb.Execu te "UPDATE TABLE1 SET PUSHFLAG = 1 WHERE ID = " & Me.ID & ";"
2) Runs an insert query to insert "all records with pushFlag = 1"
into table2. (this would create a copy of the record)
Table2 will need the PUSHFLAG column.

CurrentDb.Execu te "INSERT INTO TABLE2 IN '<PATH>' FROM TABLE1 WHERE
PUSHFLAG = 1;"
3) Sets the "status" field in the new record in table2 to a specific
value. ("done" for now)
CurrentDb.Execu te "UPDATE TABLE2 SET STATUS = 'DONE' WHERE PUSHFLAG = 1;"
4) Runs a delete query that first checks for duplicates (records that
exist in both the table1 and table2) and if a duplicate is found the
table1 record is removed. If a duplicate is not found, then the insert
must have failed for some reason. Instead of deleting the record the
user is notified that the insert failed, probably because of mal-formed
data in the record.
Why not just scan Table2 for "done"?

Either way, you will need a key that is /not autonumber/ to identify
matching records. Let's assume ID is the key in both tables, but is not
autonumber.

CurrentDb.Execu te "DELETE FROM TABLE1 WHERE ID IN (SELECT ID FROM TABLE2
WHERE STATUS = 'DONE';"

I didn't work in the user notification piece.
>
Does this sound remotely feasible? Would anyone be willing to help me
get this to work?


--
Smartin
Jul 27 '06 #8
Smartin wrote:
Jo*********@gma il.com wrote:
>I am trying to move a record from one linked table to another within
access, but I'm a complete beginner to VBA and don't know exactly where
to begin.

I have an access file that has the two linked tables, which each link
to separate SQL databases using separate ODBC connections.

I have a form that has a view of table1 and a set of buttons for
manipulating the data in database1.

The tough part is the button that's going to go on this form which
moves the record that's currently being viewed into a new record in
table2 (database2).

You can do this.
>Through extensive testing I thought I found it's impossible to simply
do this with the built-in form builder tools - it only works if one of
the tables are local and not linked. However, queries which manipulate
data between linked tables work fine, which is what gave me the notion
I could do this with a little VBA code and a couple custom queries.

So far, the plan is the make the button do this:
1) Set a "pushFlag" column in the record in table1 to a specific
identifying value ("1" for now)

This is all untested.
....as evidenced by the fact that I committed a glaring error or two (^:
(see #4)

In the button click event try the following:
>
CurrentDb.Execu te "UPDATE TABLE1 SET PUSHFLAG = 1 WHERE ID = " & Me.ID &
";"
>2) Runs an insert query to insert "all records with pushFlag = 1"
into table2. (this would create a copy of the record)

Table2 will need the PUSHFLAG column.

CurrentDb.Execu te "INSERT INTO TABLE2 IN '<PATH>' FROM TABLE1 WHERE
PUSHFLAG = 1;"
>3) Sets the "status" field in the new record in table2 to a specific
value. ("done" for now)

CurrentDb.Execu te "UPDATE TABLE2 SET STATUS = 'DONE' WHERE PUSHFLAG = 1;"
>4) Runs a delete query that first checks for duplicates (records that
exist in both the table1 and table2) and if a duplicate is found the
table1 record is removed. If a duplicate is not found, then the insert
must have failed for some reason. Instead of deleting the record the
user is notified that the insert failed, probably because of mal-formed
data in the record.

Why not just scan Table2 for "done"?

Either way, you will need a key that is /not autonumber/ to identify
matching records. Let's assume ID is the key in both tables, but is not
autonumber.

CurrentDb.Execu te "DELETE FROM TABLE1 WHERE ID IN (SELECT ID FROM TABLE2
WHERE STATUS = 'DONE';"
Should be
CurrentDb.Execu te "DELETE FROM TABLE1 WHERE ID IN (SELECT ID FROM
[<PATH>].TABLE2 WHERE STATUS = 'DONE';"
>
I didn't work in the user notification piece.
>>
Does this sound remotely feasible? Would anyone be willing to help me
get this to work?



--
Smartin
Jul 27 '06 #9
Smartin wrote:
Jo*********@gma il.com wrote:
>I am trying to move a record from one linked table to another within
access, but I'm a complete beginner to VBA and don't know exactly where
to begin.

I have an access file that has the two linked tables, which each link
to separate SQL databases using separate ODBC connections.

I have a form that has a view of table1 and a set of buttons for
manipulating the data in database1.

The tough part is the button that's going to go on this form which
moves the record that's currently being viewed into a new record in
table2 (database2).

You can do this.
>Through extensive testing I thought I found it's impossible to simply
do this with the built-in form builder tools - it only works if one of
the tables are local and not linked. However, queries which manipulate
data between linked tables work fine, which is what gave me the notion
I could do this with a little VBA code and a couple custom queries.

So far, the plan is the make the button do this:
1) Set a "pushFlag" column in the record in table1 to a specific
identifying value ("1" for now)

This is all untested.
Sorry, some stoopid things I missed...

In the button click event try the following:
>
CurrentDb.Execu te "UPDATE TABLE1 SET PUSHFLAG = 1 WHERE ID = " & Me.ID &
";"
>2) Runs an insert query to insert "all records with pushFlag = 1"
into table2. (this would create a copy of the record)

Table2 will need the PUSHFLAG column.

CurrentDb.Execu te "INSERT INTO TABLE2 IN '<PATH>' FROM TABLE1 WHERE
PUSHFLAG = 1;"
>3) Sets the "status" field in the new record in table2 to a specific
value. ("done" for now)

CurrentDb.Execu te "UPDATE TABLE2 SET STATUS = 'DONE' WHERE PUSHFLAG = 1;"
Should be

CurrentDb.Execu te "UPDATE TABLE2 IN '<PATH>' SET STATUS = 'DONE' WHERE
PUSHFLAG = 1;"
>
>4) Runs a delete query that first checks for duplicates (records that
exist in both the table1 and table2) and if a duplicate is found the
table1 record is removed. If a duplicate is not found, then the insert
must have failed for some reason. Instead of deleting the record the
user is notified that the insert failed, probably because of mal-formed
data in the record.

Why not just scan Table2 for "done"?

Either way, you will need a key that is /not autonumber/ to identify
matching records. Let's assume ID is the key in both tables, but is not
autonumber.

CurrentDb.Execu te "DELETE FROM TABLE1 WHERE ID IN (SELECT ID FROM TABLE2
WHERE STATUS = 'DONE';"
Should be

CurrentDb.Execu te "DELETE FROM TABLE1 WHERE ID IN (SELECT ID FROM
[<PATH>].TABLE2 WHERE STATUS = 'DONE';"
>
I didn't work in the user notification piece.
>>
Does this sound remotely feasible? Would anyone be willing to help me
get this to work?



--
Smartin
Jul 27 '06 #10

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

Similar topics

0
1220
by: bobb | last post by:
(I'm a long term newbie :) ) I wanted to copy a blob's contents in mysql in python from one record to another. I had a heck of a time with it, so I wanted to post it for others. The where clause was the tricky part for me. It probably has poor syntax, but it works. (Obviously) it can be used cross table and across db's. import MySQLdb
7
11944
by: Warren Wright | last post by:
Hello, We maintain a 175 million record database table for our customer. This is an extract of some data collected for them by a third party vendor, who sends us regular updates to that data (monthly). The original data for the table came in the form of a single, large text file, which we imported. This table contains name and address information on potential
0
1227
by: SJM | last post by:
In the past I have in the occasions when I had to update the values in one record from another record in the same table, I have used recordsets when in Aceess. I done something similar in SQLServer using a query like the one below. Neither of the 2 sql statements below will work with Access. I would prefer to be able to handle this with a query. I'd be grateful if someone could list some sql that I could use in Access. UPDATE...
10
2626
by: jaYPee | last post by:
as of now i am using a stored procedure from my sql server 2000 to insert record from another table. what i need now is on how can i insert record by not using the stored procedure and insert it using dataset. here is my code in stored procedure.. CREATE PROCEDURE AddRegularLoad @SchYrSemID as int, @ProgramID as int, @Sem as varchar(50), @Year as
2
2480
by: Prabu Subroto | last post by:
Dear my friends... I created a table (named : sven1). I want to populate this table with the record from another table (named : appoinment). but I don't know how to formulate the sql query. I tried this one: insert into sven1 (custid, noapp) values ((select custid from appointment where done='N' and
0
863
by: Dhanasekaran B | last post by:
Hi, I need to move one table in one server(Live) to another server(Development) through Visual basic coding. Please send soultion for this
5
4289
by: trixb | last post by:
Hello all, Here is what I need to do and need help with: I have a table that is feeding a chart in a report in Access. If this table has more than 50 records, the graph gets messy, and this is where I need help with my solution to this. If the table has more than 50 records, I want to take the next 50 records after the 50th and move these to another table (which I need to create), and this will continue until there are no more records. I...
0
2106
by: mukeshrasm | last post by:
Hi I wanted to move record up or down or top or bottom if user selects up or down or top or bottom from select box. records are coming from database. while saving record I am assigning no. to every record like 1,2,3,...45,etc. It is not the case that every record will get increamented no. It may some record can be stored with same value like 35 some like 17 and so on. and records are retrieved based on this no. means in ascending...
1
2097
by: Ryno Bower | last post by:
Hi,* I have problems to search for a record from another form. * I have a form called "Quote".* When I want to search for a quote there is a search button which opens another datasheet form with a list of all the quotes, and the first column (QuoteNo) is like a hyperlink.* So when I click on the specific quote no I want to go to on the "Quote" form it wont do the command. * The QuoteNo is a Autonumber field - I don't know if that is why?* I...
0
8397
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8732
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...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
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
7333
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
4315
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2731
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
1957
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1620
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.