Populate data in 1 table based on the data in another

Posted on 2003-02-28
Medium Priority
Last Modified: 2007-12-19
I have a form that has a sub form.  Each is based upon different tables.  What I would like to do is update the fields in the sub form with the fields selected on the main form.  

An example would be:  Click on field one in the main form and have this value pasted into field one in the sub form.

It would be nice to use the OnClick function to do this.  Is this possible? And if so, how do is it done?  The fields are the same name and data types in both the form and sub form.

Question by:caseo
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
  • 2
  • 2

Expert Comment

ID: 8043242
Hi Caseo,

You said that the fields are exactly the same in the form and subform.  Are you just trying to duplicate the information in one table to another?  Could you give some examples of your data as well as table set-up info?


Expert Comment

ID: 8043455
maybe this might help:

step 1:
set up intermediary form "intermed form" with the necessary fields, etc

step 2:
copy the date for field a from "form1" the original form where you are typing data to "intermed form" which is in turn populating a "table_intermed"

step 3:
have yr subform pull the updated data from "table_intermed"

here's code i've used to do just that:

I'm in Spain so some code is in Castillian it happens automatically:

Private Sub guardar_Click()
On Error GoTo Err_guardar_Click

' Dim destino As Form
' Set destino = Forms!FormularioRecogidas
    DoCmd.OpenForm "FormularioRecogidas"
    DoCmd.GoToRecord , , acNewRec
    Forms!FormularioRecogidas!J_NUMBER = Me!J_NUMBER
    Forms!FormularioRecogidas!J_CUSTOMER = Me!J_CUSTOMER
    Forms!FormularioRecogidas!J_TITLE1 = Me!J_TITLE1
    Forms!FormularioRecogidas!ORDERED = Me!ORDERED
    Forms!FormularioRecogidas!RECEIVED = Me!RECEIVED
    Forms!FormularioRecogidas!STATUS = Me!STATUS
    Forms!FormularioRecogidas!SUPPLIER = Me!SUPPLIER
    Forms!FormularioRecogidas!RAISED = Me!RAISED
    Forms!FormularioRecogidas!ITEM = Me!ITEM
    Forms!FormularioRecogidas!BUYER = Me!BUYER
    Forms!FormularioRecogidas!PO_NUM = Me!PO_NUM
    Forms!FormularioRecogidas!LINE = Me!LINE
    Forms!FormularioRecogidas!dia = Me!dia
    Forms!FormularioRecogidas!hora = Me!hora
    Forms!FormularioRecogidas!ENVIO_RECOGIDA = Me!ENVIO_RECOGIDA
    Forms!FormularioRecogidas!Hrealizado = Now
    Forms!FormularioRecogidas!unit = Me!unit
    If Me!coment <> "" Then
        Forms!FormularioRecogidas!coment = Me!coment
    End If
    Forms!FormularioRecogidas!compro = Me!compro

    DoCmd.Close acForm, "FormularioRecogidas"

    Me!hora = ""
    Me!coment = ""
    Me!compro = False
    Exit Sub

    MsgBox Err.Description
    Resume Exit_guardar_Click
End Sub

Author Comment

ID: 8043702
Here is a sample of the data I am unsing and the fields involved.

In the main form:
ComboBox One is pulled from a table.field - Codes.Class
ComboBox Two is pulled from a table.field - Codes.Sclass
ComboBox Three is pulled from a table.field - Codes.Fcodes

In the Sub Form:
ListBox One is Ecodes.Class
ListBOx Two is Ecodes.Sclass
ListBox Three is Ecodes.Fcodes

When I select from the main form Codes.Class, I have SQL statments and VBA code that pulls the related Sclass and a selection of Fcode.  When I click on the correct Fcode, I would like to have the three list boxes in the Sub Form updated with the data selected in the Main form.

Accepted Solution

CEGE earned 150 total points
ID: 8044537
create a form called "ecodes_update" with bound field names to the Ecodes Table. then create a button, called update, which onclick runs the following:

Private Sub save_Click()

   DoCmd.OpenForm "ecodes_update"
   DoCmd.GoToRecord , , acNewRec
   Forms!ecodes_update!Class = Me!Class
   Forms!ecodes_update!Sclass = Me!Sclass
   Forms!ecodes_update!Fcodes= Me!Fcodes

   DoCmd.Close acForm, "ecodes_update"

   Me!Class = ""
   Me!Sclass = ""
   Me!Fcodes= False

End Sub
then link your subform to your main form via a unique link object

hope this helps


Author Comment

ID: 8065137
I want to thank you for your input, but I could not get this answer to work for me, I give you the points for your help.  Thanks

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
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.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Suggested Courses

764 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