Solved

Macro to copy data from one field to another

Posted on 2014-03-26
7
1,516 Views
Last Modified: 2014-04-22
I have a form based on a query involving 3 tables (1 table connecting the other 2). What I need is a macro or event that I can assign to a button that will copy data from a few fields from one table to a few fields in the other table. This will be a common occasion for this data base so I want a button that can be run easily for the user.

Thanks!
0
Comment
Question by:cozmo_troll
  • 4
  • 3
7 Comments
 
LVL 84
ID: 39957707
You can write data to a table like this:

Currentdb.Execute "UPDATE DestinationTable SET Field1=" & Me.tx1 & " WHERE IDField=" & SomeIDVAlue

However, you have to know those valuse (i.e. the IDField, SomeIDValue, etc).

If you can provide a little more information we might be able to suggest better ways.
0
 

Author Comment

by:cozmo_troll
ID: 39959135
What I have are two separate tables; one for anticipated shipments and one for actual shipments. I want to be able to do a record by record button that would copy data from a few fields on the anticipated table to the actual table once the user confirmed the information was accurate. For example: Ship To Destination to Ship To Destination and so on.
0
 
LVL 84
ID: 39960395
Would the record in the "actual shipments" table already exist? Or would you create it?

If it already exists, you can just Update it:

Currentdb.Execute "UPDATE ShipTable SET Ship_To = "& Me.Ship_To & " WHERE SomeIDFIeld=" & Me.YourIDValue

But - again - you'll have to know the value of YourIDValue to pinpoint the record in the "ShipTable" table. Or, if you know sufficient details to pinpoint that record otherwise, you could use those. For example, perhaps the Customer+OrderDate+Material is enough to point you to the right record. If so, you could use those instead of YourIDValue.

A better solution, however, might be to include a "Type" field in one table, and set it to various values depending on the status of the shipment. For example, you might set "Type='Pending'" for "anticipated shipments", and then change "Type='Shipped'" when that line actually goes out the door.

Or go one step further and use a "Transaction" table, where you add records whenever anything is moved in the system (sort of like a Journal table for shipments).
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:cozmo_troll
ID: 39962212
I have an issue because I have orders and shipments. Orders have anticipated shipment details on them but because each shipment can container multiple orders I don't think I can simply change a status from Pending to Shipped without showing which shipment it belongs to. Right now I have a detail table that has an ID field, OrderID field, and Shipment ID field that ties them all together. Basically, I'm just trying to make it simple for the user so when they do the shipment they can copy the shipment data from the orders table to the shipments table. The problem is that there is no field that ties the two tables together besides the ID field in the detail table. so, i don't know how to adjust your expression to reflect that.
0
 
LVL 84
ID: 39962458
If your intent is to copy details from one table to another, then the code example I provided would give you that. If that doesn't work, then you'd have to give us a little more to go on. A sample of your database would be helpful, but if you do that be sure to remove or change any sensitive data.

In general, an Ordering system would have a Header and Detail table. You'd then have something like a Packing table, where you would assemble a "Packlist" made up of a single PacklistHeader with multiple Details (and each of those Details could come from a different Order).

The Packlist table would, essentially, be your Shipping table. You could relate each Packlist Detail line back to a single Order Detail line.

To me, that's the right way to create a system like this - but of course each situation is different, so if you'd give us more info we might be able to help further.
0
 

Author Comment

by:cozmo_troll
ID: 39962586
I agree that your example should work, but there is no SomeIDFIeld=" & Me.YourIDValue
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 39963692
You could use one or more other fields. For example:

UPDATE ShipTable SET SomeField=SomeValue WHERE Field1=" & me.txField1 &  " AND Field2=" & Me.txField2

If you cannot do that - i.e. if you cannot identify which record in ShipTable is related to the record you're working with in the Order table - then you have a flaw in your design.

But we really can't help more unless we can see the design. If you could upload a copy of your database that would be most helpful. If you do, be sure to obfuscate any sensitive data like names, address, phone numbers, etc.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now