change a subform recordsource on click (1 Viewer)

Manos39

Registered User.
Local time
Today, 13:40
Joined
Feb 14, 2011
Messages
248
Hi,
i would like help to change a subform's recordsource by clicking a command button in my main form.
Read some articles but still cannot achive it

Main form name is adeiesfrm and subform's name is adeiesfrmsub1
adeiesfrmsub1 default recordsource is adeiestbl
and i need changing that recordsource to a query named Qradeiescurrentlastyear by clicking button "Show Current and Previous Year"
here is my tests none works

Code:
Private Sub Command64_Click()
'Me.adeiesfrmsub1.Form.RecordSource = "Qradeiescurrentlastyear"
'Me.adeiesfrmsub1.Form.RecordSource = Qradeiescurrentlastyear
'Forms!adeiesfrm!adeiesfrmsub1.Form.RecordSource = "Qradeiescurrentlastyear"
'Forms!adeiesfrm!adeiesfrmsub1.Form.Requery
Forms!adeiesfrm.adeiesfrmsub1.Form.RecordSource = "Qradeiescurrentlastyear"
'Me.adeiesfrmsub1.Form.RecordSource = "Qradeiescurrentlastyear"
'Me.adeiesfrmsub1.Form.Requery

i provide my database if it is needed
 

Attachments

  • TEFKK.accdb
    2.9 MB · Views: 92

theDBguy

I’m here to help
Staff member
Local time
Today, 13:40
Joined
Oct 29, 2018
Messages
21,476
Looks to me like you can do the same by simply applying a filter to your subform instead of using a separate query for it.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 13:40
Joined
Oct 29, 2018
Messages
21,476
Is this close to what you want?
 

Attachments

  • TEFKK.zip
    420.2 KB · Views: 81

Manos39

Registered User.
Local time
Today, 13:40
Joined
Feb 14, 2011
Messages
248
Looks to me like you can do the same by simply applying a filter to your subform instead of using a separate query for it.
Yes it is quite close, only it is missing records if opened side by side Qradeiescurrentlastyear and main form with filter applied for the same person
that query has : WHERE (((DateDiff("yyyy",[Enarxi],Date())<=1)=True))
Your solution is fantastic but i would prefer solving that problem as i intended to, so i could use it somewhere in future...
 

theDBguy

I’m here to help
Staff member
Local time
Today, 13:40
Joined
Oct 29, 2018
Messages
21,476
Yes it is quite close, only it is missing records if opened side by side Qradeiescurrentlastyear and main form with filter applied for the same person
that query has : WHERE (((DateDiff("yyyy",[Enarxi],Date())<=1)=True))
Your solution is fantastic but i would prefer solving that problem as i intended to, so i could use it somewhere in future...
I didn't want to use the same criteria, but I guess I have to. Try it now...
 

Attachments

  • TEFKK (2).zip
    427.7 KB · Views: 73

LarryE

Active member
Local time
Today, 13:40
Joined
Aug 18, 2021
Messages
592
Hi,
i would like help to change a subform's recordsource by clicking a command button in my main form.
Read some articles but still cannot achive it

Main form name is adeiesfrm and subform's name is adeiesfrmsub1
adeiesfrmsub1 default recordsource is adeiestbl
and i need changing that recordsource to a query named Qradeiescurrentlastyear by clicking button "Show Current and Previous Year"
here is my tests none works

Code:
Private Sub Command64_Click()
'Me.adeiesfrmsub1.Form.RecordSource = "Qradeiescurrentlastyear"
'Me.adeiesfrmsub1.Form.RecordSource = Qradeiescurrentlastyear
'Forms!adeiesfrm!adeiesfrmsub1.Form.RecordSource = "Qradeiescurrentlastyear"
'Forms!adeiesfrm!adeiesfrmsub1.Form.Requery
Forms!adeiesfrm.adeiesfrmsub1.Form.RecordSource = "Qradeiescurrentlastyear"
'Me.adeiesfrmsub1.Form.RecordSource = "Qradeiescurrentlastyear"
'Me.adeiesfrmsub1.Form.Requery

i provide my database if it is needed
Try:
Forms![adeiesfrm]![adeiesfrmsub1].Form.RecordSource = "Qradeiescurrentlastyear"
Forms![adeiesfrm]![adeiesfrmsub1].Form.Requery
 

theDBguy

I’m here to help
Staff member
Local time
Today, 13:40
Joined
Oct 29, 2018
Messages
21,476
I didn't want to use the same criteria, but I guess I have to. Try it now...
Okay, compare that to the criteria I really want to use.
 

Attachments

  • TEFKK (3).zip
    427.8 KB · Views: 94

Users who are viewing this thread

Top Bottom