By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,107 Members | 1,323 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,107 IT Pros & Developers. It's quick & easy.

Access can't find subform

P: 4
I'm using a search engine in VBA to return a new RecordSource to a SubForm, but when I attempt to apply the new SQL code as the RecordSource to the SubForm which contains the data the user wants to see, Access (VBA) returns an error that the form can't be found (even though the form is open and displayed on the screen).

Here is the code:
Expand|Select|Wrap|Line Numbers
  1. If Trim(txtMaterialNumber.Text) = "" Then
  2.          MsgBox "Criteria Must Be Entered Before Performing A Search", 
  3.           vbInformation, "Enter Criteria"        
  4. Else
  5.         strRecordSource = SetupOperatingSuppliesSearchQuery(True, False, 
  6.         Forms![OperatingSupplies].Form.RecordSource = strRecordSource
  7. End If
  8.  
  9.  
  10. Forms![OperatingSupplies].Form.RecordSource = strRecordSource
  11.  
  12. Me.Requery
Dec 22 '08 #1
Share this Question
Share on Google+
9 Replies


FishVal
Expert 2.5K+
P: 2,653
Is your [OperatingSupplies] form in datasheet view?
Dec 22 '08 #2

DonRayner
Expert 100+
P: 489
You need to refer to the subform by refering to it's main form first

Expand|Select|Wrap|Line Numbers
  1. Forms!MainForm.Form!OperatingSupplies.RecordSource = strRecordSource
  2.  
Dec 22 '08 #3

P: 4
No, the main form is a "container" form which has 3 subforms. It is layed-out in an Outlook style with some icons running down the left side, continous form data in the middle form, and then a search engine form at the top.

They are also all independent of each other (in other words, no keys or data fields tying any of the 3 together). Everything will be handled in code.
Dec 22 '08 #4

FishVal
Expert 2.5K+
P: 2,653
Sorry, didn't pay attention to hoe you get reference to it.
Take a look at DonRayner's suggestion.
Form opened in a subform control is not been added to Forms collection.
So, it should be referenced via Form property of the subform control.

Regards,
Fish
Dec 22 '08 #5

P: 4
Don,

I tried the code you posted and I received an 'Object does not support this property or method' error (after inserting the name of my mainform in place of the code you sent first of course). I can't remember how to do this because I've been away from Access coding for so long.
Dec 22 '08 #6

P: 4
I figured out a solution:
Expand|Select|Wrap|Line Numbers
  1.     Dim frm As Form_OperatingSupplies
  2.  
  3.     Set frm = Form_OperatingSupplies
  4.  
  5.     frm.RecordSource = strRecordSource
  6.  
  7.     frm.Requery
Seems to be working perfectly. Thanks for the help though. It set me on the right path to my solution after realizing that the form needed to be dimensioned as it's own individual Object.

-Chris
Dec 22 '08 #7

NeoPa
Expert Mod 15k+
P: 31,419
Referring to Items on a Sub-Form may help with such references.

Welcome to Bytes!
Dec 22 '08 #8

P: 1
Chickenhawk if you ever revisit this post, your own solution sorted my similar problem which had cost me hours. Many thenks!
Aug 12 '10 #9

NeoPa
Expert Mod 15k+
P: 31,419
Always nice to hear when people find anything we have to be helpful BP.

Thanks for posting and welcome to Bytes!
Aug 12 '10 #10

Post your reply

Sign in to post your reply or Sign up for a free account.