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

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 24585
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*********@gmail.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.OpenRecordset("FirstTable")
Set rec2 = db.OpenRecordset("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...@gmail.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.OpenRecordset("FirstTable")
Set rec2 = db.OpenRecordset("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.openrecordset ("Select * from Table1 where ID = " &
me.TableID & "")

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

Jo*********@gmail.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.OpenRecordset("FirstTable")
Set rec2 = db.OpenRecordset("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*********@gmail.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.Execute "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.Execute "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.Execute "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.Execute "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*********@gmail.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.Execute "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.Execute "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.Execute "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.Execute "DELETE FROM TABLE1 WHERE ID IN (SELECT ID FROM TABLE2
WHERE STATUS = 'DONE';"
Should be
CurrentDb.Execute "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*********@gmail.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.Execute "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.Execute "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.Execute "UPDATE TABLE2 SET STATUS = 'DONE' WHERE PUSHFLAG = 1;"
Should be

CurrentDb.Execute "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.Execute "DELETE FROM TABLE1 WHERE ID IN (SELECT ID FROM TABLE2
WHERE STATUS = 'DONE';"
Should be

CurrentDb.Execute "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
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...
7
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...
0
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...
10
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...
2
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. ...
0
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
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...
0
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...
1
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...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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:
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
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.