Solved

Macro to copy data from one field to another

Posted on 2014-03-26
7
1,618 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…

735 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