Automatically fill main form when data is entered in subform

ahmad_rmh

Member
Local time
Today, 21:04
Joined
Jun 26, 2022
Messages
243
I am trying to fill main form as data is entered in subform but i am getting error

I have applied code in the subform on dirty event as under.

Code:
Private Sub Form_Dirty(Cancel As Integer)
    With Me.Parent
        If IsNull(!RefPK) Then
            If Me.Parent.lblReference.Caption = "Receipt" Then
                Me.Parent.TranTypeFK.DefaultValue = 1
                Me.Parent.TypeRef = "Test"
                Me.Parent.Frame1.DefaultValue = 1
                Me.Dirty = False
            End If
        End If
    End With
End Sub

But TranTypeFK combo box getting blank as I change in subform and generates error.

The screenshots are attached herewith before to run the code and after.

How to fill also combo box automatically as described in the code.[/CODE]
 

Attachments

  • Capture1.JPG
    Capture1.JPG
    76.9 KB · Views: 142
  • Capture2.JPG
    Capture2.JPG
    85 KB · Views: 144
  • Capture3.jpg
    Capture3.jpg
    103.8 KB · Views: 143
Last edited:
You can't create child records without a parent record first?
Think about it logically, there is no Foreign Key available for the child at that point.
 
if you will see the second image the id has been generated with the dirty code on subform it's working but making it blanks the combo box.

So, I am sure, may be a technique is available to handle this issue.
 
if you will see the second image the id has been generated with the dirty code on subform it's working but making it blanks the combo box.

So, I am sure, may be a technique is available to handle this issue.
As stated by Minty you have to have a Parent record on the Main Form before you can add a record to the Subform.
 
RI is only enforced if you define it in the Relationship diagram in the BE. If you do not define a relationship and enforce RI between the parent and child tables, you can add an orphan to the child record.

Should you? absolutely not! And what are you going to do when you add the second record to the subform? Overwrite the value placed in the pseudo parent by the first pseudo child? Not to mention the fact that Me.Dirty = False is saving the child record, not the parent record.

It might be time to rethink this process. If certain fields will be the same for all "child" records, then they belong in the parent record so enter them there. Why duplicate them in every child record?
 
So, I am sure, may be a technique is available to handle this issue.

The question is not whether there is a way, but whether there is a way that a person unfamiliar with Access would really want to design, build, and maintain. Access is designed to follow general industry "best practices" that include things like "parent records must be defined before child records." If you prefer "sub-records" to "child records" we can live with that naming convention. But Access strength comes when you do things in the way that most of the industry does things. Defining sub-records first is NOT the industry best practice.
 

Users who are viewing this thread

Back
Top Bottom