UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Relationship, Access 2010    
 
   
ClaudioHenriques
post May 1 2019, 05:25 PM
Post#1



Posts: 86
Joined: 9-August 16



Dear, my question is about how to insert data into a table that receives a relationship.

Example, I have a table that I call tab1 and it has a key field that relates to another one that I call tab2, in the one-to-many relationship.
With this configuration I make 2 forms and I consider one as a subform introducing it in the first one.
So I relate the parent and child fields of form and subform.

My question is, how does this relationship get when I do not use a subform?

If I use a form to display the tab1 and a button to load another form to load the tab2 ... how does the relationship?

thanks

Go to the top of the page
 
RJD
post May 1 2019, 05:52 PM
Post#2


UtterAccess VIP
Posts: 9,751
Joined: 25-October 10
From: Gulf South USA


Hi: The easiest way, of course, is to use the subform approach, with a master/child relationship. That can make the relationship automatic.
However, if you choose to use separate forms, then table Tab1 will should remain open when table Tab2 is opened. One method I have used is, when Tab2 is opened, the relationship ID is copied to an unbound text control on Tab2. This can be done with code following the command to open Tab2.

Then you can use code, in an event that creates the new record, to copy the relationship ID to the new record - from either the Tab2 header control ID contents, or if you do not use that approach, from the appropriate Tab1 control.

I favor copying the ID to a Tab2 control so I can make a visual confirmation that I am using the correct value. But mostly, I just use the subform approach as being much easier.

Just some thoughts ...

HTH
Joe

--------------------
"Each problem that I solved became a rule, which served afterwards to solve other problems."
"You just keep pushing. You just keep pushing. I made every mistake that could be made. But I just kept pushing."

Rene Descartes 1596-1650 (Mathematician and Philosopher)
Go to the top of the page
 
ClaudioHenriques
post May 2 2019, 08:47 AM
Post#3



Posts: 86
Joined: 9-August 16



Thanks for the RJD reply.

So I had thought the same, but I tested it in one example and I noticed error.Maybe you can help me.

Tables: tbEmp ..... frm_Proc (form)
Tables: tbPb ...... frm_Pb


There is a record in the tbEmp : "D.001.2018" (Id=4)
There is a record in the tbPb : "D.001.2018" (IdEmp=4)

the tbEmp table has relationship to the tbPb table.(united fields equal)


testing....

Open frm_Proc ... button "NEW" ..............will be created "D.002.2018"

now push the button "OPEN"

open the form "frm_Pb" and displays the related record if SeqLocal in tbPb exist testing the form field frm_Proc/SeqLocal

if it exists it displays the form at where frm_Pb/SeqLocal=frm_Proc/SeqLocal


if there is not..
open the form "frm_Pb" and write in the fields :

frm_Pb.SeqLocal with the value of frm_Proc.SeqLocal
frm_Pb.IdEmp with the value of frm_Proc.Id ......(campo relação)

At this point I can not save the record.

attached database




Attached File(s)
Attached File  Database1.zip ( 36.7K )Number of downloads: 4
 
Go to the top of the page
 
RJD
post May 2 2019, 12:25 PM
Post#4


UtterAccess VIP
Posts: 9,751
Joined: 25-October 10
From: Gulf South USA


Hi: The child record cannot be saved because there is a relationship between the tables with referential integrity enforced, and you have not yet saved the new master record. In the Open button code, add a line to save the new master record before opening the second form and posting the values to the new record ...

CODE
Private Sub Cria_PB_Click()

If Me.Dirty = True Then Me.Dirty = False

...etc...

This will save the master record if it is a new one or an existing record has changed. Then the child record can be saved.

See the revision to your db attached.

HTH
Joe
Attached File(s)
Attached File  UA_CH_20190502.zip ( 45.89K )Number of downloads: 6
 

--------------------
"Each problem that I solved became a rule, which served afterwards to solve other problems."
"You just keep pushing. You just keep pushing. I made every mistake that could be made. But I just kept pushing."

Rene Descartes 1596-1650 (Mathematician and Philosopher)
Go to the top of the page
 
ClaudioHenriques
post May 3 2019, 05:35 AM
Post#5



Posts: 86
Joined: 9-August 16



RJD , You, really clear my vision on the subject, thank you.
Go to the top of the page
 
RJD
post May 3 2019, 07:44 AM
Post#6


UtterAccess VIP
Posts: 9,751
Joined: 25-October 10
From: Gulf South USA


You are very welcome. Continued success ...

Regards,
Joe

--------------------
"Each problem that I solved became a rule, which served afterwards to solve other problems."
"You just keep pushing. You just keep pushing. I made every mistake that could be made. But I just kept pushing."

Rene Descartes 1596-1650 (Mathematician and Philosopher)
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    23rd July 2019 - 08:30 AM