Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 874
  • Last Modified:

Populate data in 1 table based on the data in another

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.

Thanks
0
caseo
Asked:
caseo
  • 2
  • 2
1 Solution
 
miller11946Commented:
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?

Robyn
0
 
CEGECommented:
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
    Me.Refresh
    Me!dia.SetFocus
   
Exit_guardar_Click:
    Exit Sub

Err_guardar_Click:
    MsgBox Err.Description
    Resume Exit_guardar_Click
   
End Sub
0
 
caseoAuthor Commented:
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.
0
 
CEGECommented:
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
   Me.Refresh
   Me!Class.SetFocus

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

hope this helps

jis
0
 
caseoAuthor Commented:
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
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now