?
Solved

Macro to copy data from one field to another

Posted on 2014-03-26
7
Medium Priority
?
1,865 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 85
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 85
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 

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 85
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 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have had my own IT business for a very long time. I started mostly with hardware and after about a year started to notice a common theme. I had shelves with software boxes -- Peachtree, Quicken, Sage, Ouickbooks -- and yet most of my clients were…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…

601 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