Connecting Tech Pros Worldwide Forums | Help | Site Map

Access can't find subform

Newbie
 
Join Date: Dec 2008
Posts: 4
#1: Dec 22 '08
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

FishVal's Avatar
Expert
 
Join Date: Jun 2007
Location: Israel
Posts: 2,584
#2: Dec 22 '08

re: Access can't find subform


Is your [OperatingSupplies] form in datasheet view?
DonRayner's Avatar
Expert
 
Join Date: Sep 2008
Location: Canada
Posts: 494
#3: Dec 22 '08

re: Access can't find subform


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.  
Newbie
 
Join Date: Dec 2008
Posts: 4
#4: Dec 22 '08

re: Access can't find subform


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.
FishVal's Avatar
Expert
 
Join Date: Jun 2007
Location: Israel
Posts: 2,584
#5: Dec 22 '08

re: Access can't find subform


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
Newbie
 
Join Date: Dec 2008
Posts: 4
#6: Dec 22 '08

re: Access can't find subform


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.
Newbie
 
Join Date: Dec 2008
Posts: 4
#7: Dec 22 '08

re: Access can't find subform


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
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,747
#8: Dec 22 '08

re: Access can't find subform


Referring to Items on a Sub-Form may help with such references.

Welcome to Bytes!
Reply