Solved

Macro to copy data from one field to another

Posted on 2014-03-26
7
1,680 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 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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…

636 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