Application defined or object defined error '2465' (1 Viewer)

MilaK

Registered User.
Local time
Yesterday, 16:26
Joined
Feb 9, 2015
Messages
285
Hello,

I'm trying to filter a 'single form' sub-form when the main form opens. I need the sub-form to show a participial record that is dictated by the filter criteria. The Main form opens but I get an error message and filter fails. Note: both sample_id (primary key) and run_name are strings.

Here is the vba code I'm using:

Code:
strform = "frm_combined_CNVs"

Criteria = "[sample_id] = '" & empty_sample1 & "' AND [run_name] = '" & Me.txt_Run_Name.Value & "'"
Debug.Print Criteria

DoCmd.OpenForm strform

Application.Echo False
        Forms!frm_combined_CNVs.frm_sample_cnv1.Form.Filter = Criteria
        Forms!frm_combined_CNVs.frm_sample_cnv1.Form.FilterOn = True
Application.Echo True

Is the filter failing because I'm trying to filter a Single Form? Thanks, Mila
 

sneuberg

AWF VIP
Local time
Yesterday, 16:26
Joined
Oct 17, 2014
Messages
3,506
I just tried something very similar and it doesn't seem to make a difference where continuous or single form. If your code is in the form's load or open event I suggest creating the references like:

Code:
 Me.frm_sample_cnv1.Form.Filter = Criteria
 Me.frm_sample_cnv1.Form.FilterOn = True

So Intellisense will let you know if you are getting them right.

If this code is not in the form's load or open event then is the form and subform open when this code is run?


On what line is the error occurring?
 

MilaK

Registered User.
Local time
Yesterday, 16:26
Joined
Feb 9, 2015
Messages
285
I can get the form to open. I get an error message and the
Code:
Forms!frm_combined_CNVs.frm_sample_cnv1.Form.Filter = Criteria1
is highlighter.

I also tried this method without success: DoCmd.OpenForm
Code:
"frm_combined_CNVs", , , "Forms!frm_combined_CNVs.frm_sample_cnv1.Form.[sample_id] = '" & sample_id & "'

I'm attaching a sample database. All patient related information has been removed. "Form1" button contains the code that opens "frm_combined_CNVs" form.

Any advice/suggestions will be greatly appreciated.

Thanks for your help, Mila
 

Attachments

  • Example_Db.zip
    193 KB · Views: 102

sneuberg

AWF VIP
Local time
Yesterday, 16:26
Joined
Oct 17, 2014
Messages
3,506
Your references weren't correct. Try

Code:
Forms![frm_combined_CNVs]![frm_sample_cnv].[Form].Filter = Criteria1
Forms![frm_combined_CNVs]![frm_sample_cnv].[Form].FilterOn = True

I think it's better if you give the subform and the form in it the same name. In this case the form was frm_sample_cnv1 but the subform was frm_sample_cnv. The subform control is what goes in the reference. This link might help you in the future.
 

MilaK

Registered User.
Local time
Yesterday, 16:26
Joined
Feb 9, 2015
Messages
285
Thanks, everything works now!

Quick question...

Do you think it's a bad idea to include this many subform on a single form? Do you think it might take a very long time to load when the database will get larger?

We should be upgraded on Office 2016 soon, not sure if that's important.

Thanks,

Mila
 

sneuberg

AWF VIP
Local time
Yesterday, 16:26
Joined
Oct 17, 2014
Messages
3,506
Thanks, everything works now!

Quick question...

Do you think it's a bad idea to include this many subform on a single form? Do you think it might take a very long time to load when the database will get larger?

We should be upgraded on Office 2016 soon, not sure if that's important.

Thanks,

Mila

I don't know or have an opinion on either of these. I suggest you start new threads with these questions?

Glad it's working for you.
 

Users who are viewing this thread

Top Bottom