Populate Subform with MainForm Data (1 Viewer)

mfaisal.ce

Member
Local time
Tomorrow, 01:00
Joined
Dec 21, 2020
Messages
76
Dear Friends,

I have a main form with subform, what i need is when i change value of main form and record exits then populate data for subform based on main form value else clear subform for new data entry....
Kindly guide,

Main Form: FrmSales
Main Form Field: SNo (Primary Key)

Subform : FrmSales_Detail
Subform Field: SNo (Foreign Key)

Subform: FrmPayment_Detail
Subform Field: SNo (Foreign Key)

regards,
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:00
Joined
May 7, 2009
Messages
19,227
bring your form in design view.
click on the subform.
add Master/Child Link Fields using both SNo.
 

mfaisal.ce

Member
Local time
Tomorrow, 01:00
Joined
Dec 21, 2020
Messages
76
Brother,
i agree what u said.... but if works only when u do navigation in records. but if u enter any value in master field with existing record, it doesnot populate child records in subform.... this is my problem......
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:00
Joined
May 7, 2009
Messages
19,227
what value are you trying to change the SNo?
try adding relationship to your tables and
add Cascade Update to the child tables.
 

mfaisal.ce

Member
Local time
Tomorrow, 01:00
Joined
Dec 21, 2020
Messages
76
Dear,

What i need is very simple... sorry, if i am not able to elaborate my problem.... i will try again,

I have a combobox "SNO" on Main form, when ever i will write any value here... if the record with that "SNo" exits, it will populate the mainform & subform accordingly else create the new record.... Plz see the attached image

1611148349638.png
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:00
Joined
May 7, 2009
Messages
19,227
make the combobox Unbound and the Main Form bound.
on AfterUpdate event of the Sno combobox, add code:
Code:
private sub combo_afterupdate()
if me.combo.listindex > -1 then
    with me.recordsetclone
        .findfirst "sno = '" & me.combo & "'"
        if not .nomatch then
            me.bookmark = .bookmark
        end if
    end with
end if
end sub
make sure that the subform has master/child link fields.
 

mfaisal.ce

Member
Local time
Tomorrow, 01:00
Joined
Dec 21, 2020
Messages
76
thanks dear... but i cant make combobox unbound because this is bound with SNo field of master form ( Master Table "Sales" with primary key in Field "SNo"), if i will make it unbound then how i will save record in Master Table....

1. Master Table "Sales"
Fields: SNo, CustomerID

2. Child Table "Sales_Detail"
Fields: SNo, Qty, Price
 

Dreamweaver

Well-known member
Local time
Today, 23:00
Joined
Nov 28, 2005
Messages
2,466
Create a second one with the wizard as a lookup combo
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:00
Joined
May 7, 2009
Messages
19,227
the purpose of the combo is to "search" your table.
if you make it bound, it will just over-write the Current record.

you need to find a way to "add" a record if there is no
matching record when on it search.
 

mfaisal.ce

Member
Local time
Tomorrow, 01:00
Joined
Dec 21, 2020
Messages
76
the purpose of the combo is to "search" your table.
if you make it bound, it will just over-write the Current record.

you need to find a way to "add" a record if there is no
matching record when on it search.
Ok bro... Leave combobox.... Suppose i have a text box "SNO"... After update value in SNo txt box, if records exist in main form and subform then show them , else keep all blank....
 

Users who are viewing this thread

Top Bottom