473,698 Members | 2,337 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Subform Recordsource Nightmare

56 New Member
I'm having a nightmare. I've used this technique before and can't understand why I'm getting an error using it now. Basically I have a form, on that is a sub form datasheet. What I am eventually aiming to do is have a button set the Record Source of the subform.

Now the code is as follows:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Command6_Click()
  3.  
  4. SetFilter
  5.  
  6. End Sub
  7.  
  8.  
  9.  
  10. Sub SetFilter()
  11.  
  12.     Dim LSQL  As String
  13.  
  14.     LSQL = "SELECT AllProducts.Supplier, AllProducts.Manufacturer, AllTransactionData.[Product Code], First(AllTransactionData.[Product Description]) AS [Product Description], Sum(AllTransactionData.[Qty Sent]) AS Quantity, Sum(AllTransactionData.[Selling Price]) AS [Amount £], AllPrices.[Core/Wider], AllTransactionData.[Transaction Period] FROM AllPrices INNER JOIN (AllProducts INNER JOIN AllTransactionData ON AllProducts.[Product Code] = AllTransactionData.[Product Code]) ON AllPrices.[Product Code] = AllTransactionData.[Product Code] GROUP BY AllProducts.Supplier, AllProducts.Manufacturer, AllTransactionData.[Product Code], AllPrices.[Core/Wider], AllTransactionData.[Transaction Period] HAVING (((AllProducts.Manufacturer) = 'Polypipe Building Product')) ORDER BY AllTransactionData.[Transaction Period] DESC , Sum(AllTransactionData.[Qty Sent]) DESC"
  15.  
  16.     TopSalesByMonthsubform.RecordSource = LSQL
  17.  
  18. End Sub
  19.  
  20.  
Yes the select is huge, but I've literally ripped if from a query.

Its perfectly happy having that pasted into the recordsource from properties, but I can't get the subform to update from VBA.

I'm obviously doing something wrong with TopSalesByMonth subform.RecordS ource = LSQL but I can't see what. Its copied direct from past examples too.

Can anyone help?
Aug 8 '07 #1
6 2665
FishVal
2,653 Recognized Expert Specialist
I'm having a nightmare. I've used this technique before and can't understand why I'm getting an error using it now. Basically I have a form, on that is a sub form datasheet. What I am eventually aiming to do is have a button set the Record Source of the subform.

Now the code is as follows:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Command6_Click()
  3.  
  4. SetFilter
  5.  
  6. End Sub
  7.  
  8.  
  9.  
  10. Sub SetFilter()
  11.  
  12.     Dim LSQL  As String
  13.  
  14.     LSQL = "SELECT AllProducts.Supplier, AllProducts.Manufacturer, AllTransactionData.[Product Code], First(AllTransactionData.[Product Description]) AS [Product Description], Sum(AllTransactionData.[Qty Sent]) AS Quantity, Sum(AllTransactionData.[Selling Price]) AS [Amount £], AllPrices.[Core/Wider], AllTransactionData.[Transaction Period] FROM AllPrices INNER JOIN (AllProducts INNER JOIN AllTransactionData ON AllProducts.[Product Code] = AllTransactionData.[Product Code]) ON AllPrices.[Product Code] = AllTransactionData.[Product Code] GROUP BY AllProducts.Supplier, AllProducts.Manufacturer, AllTransactionData.[Product Code], AllPrices.[Core/Wider], AllTransactionData.[Transaction Period] HAVING (((AllProducts.Manufacturer) = 'Polypipe Building Product')) ORDER BY AllTransactionData.[Transaction Period] DESC , Sum(AllTransactionData.[Qty Sent]) DESC"
  15.  
  16.     TopSalesByMonthsubform.RecordSource = LSQL
  17.  
  18. End Sub
  19.  
  20.  
Yes the select is huge, but I've literally ripped if from a query.

Its perfectly happy having that pasted into the recordsource from properties, but I can't get the subform to update from VBA.

I'm obviously doing something wrong with TopSalesByMonth subform.RecordS ource = LSQL but I can't see what. Its copied direct from past examples too.

Can anyone help?
Hi, Widge.
Some additional information would be really helpful.
What error you are getting and where the code (if code at all) fails?
Do subform controls ControlSource propeties match the query fields?
Did you try to run the SQL expression in Query Builder?
Aug 8 '07 #2
Widge
56 New Member
Hi there!

The query works fine (it just looks a mess).

The error I am getting is:

Compile error:

Method or data member not found


As for the control source? I'm not sure. The recordsource is initially that query pasted into it, which displays fine as a datasheet.

Then to test the button, I set the recordsource to "" temporarily and created the little statement in the code.
Aug 9 '07 #3
FishVal
2,653 Recognized Expert Specialist
Hi there!

The query works fine (it just looks a mess).

The error I am getting is:

Compile error:

Method or data member not found


As for the control source? I'm not sure. The recordsource is initially that query pasted into it, which displays fine as a datasheet.

Then to test the button, I set the recordsource to "" temporarily and created the little statement in the code.
Hi, Widge.

Sorry, I should notice it from the very beginning.
You have a bad reference to [subform].Form.RecordSou rce property
Here is your code.
Expand|Select|Wrap|Line Numbers
  1. TopSalesByMonthsubform.RecordSource = LSQL
  2.  
1. Despite you may reference control without name of collection ("Form.Controls !" or simply "Form!" as Controls is a default property of Form), its better to explicitely refer to Controls collection.
Expand|Select|Wrap|Line Numbers
  1. Me!TopSalesByMonthsubform
  2. or
  3. Me.TopSalesByMonthsubform
  4.  
2. Above expressions return Control object which does not have RecordSource property. You need to get Form property of the Control.
Expand|Select|Wrap|Line Numbers
  1. Me.TopSalesByMonthsubform.Form.RecordSource=LSQL
  2.  
Aug 9 '07 #4
Widge
56 New Member
I think I see what you mean! I had an experiment with the me. before but it didn't help.

I will give this a go and come back with praise in a bit! :D
Aug 9 '07 #5
FishVal
2,653 Recognized Expert Specialist
I think I see what you mean! I had an experiment with the me. before but it didn't help.

I will give this a go and come back with praise in a bit! :D
Using Me. within a form module as object name of the form owner the code module is in your case more likely question of good programming style, it doesn't cause the error.
What you need to do is to enter parh to RecordSource property explicitely.
Me.[SubFormName].Form.RecordSou rce
Aug 9 '07 #6
Widge
56 New Member
Brilliant, cheers!

I knew I wasn't referencing properly!
Aug 9 '07 #7

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

Similar topics

4
2290
by: CSDunn | last post by:
Hello, I have a combo box (Combo7) that needs to call a function during the After Update event of the combo box. The function resides in an Access 2000 ADP Module called MMAnswerData_code. The following is the code of the function: Public Function SubFormRS(FrmTarget As Object) Forms!frmAD_OpeningForm!FrmTarget.RecordSource = "EXEC dbo.AdSubFormRecSource " & Forms!frmAD_OpeningForm!SubFormFilter
0
2351
by: CSDunn | last post by:
Hello, In Access ADP's that connect to SQL Server databases, any time I have a situation where I have a combo box in a main form that looks up a record in a subform, the subform record source has to be based on either a View or a Table. I can almost always use a View, and it helps to do this since I can have better control over the size of the RecordSet of the subform. There are times when the use of a Stored Procedure would give me...
25
10241
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the data in each record, which includes the ID of the father and the mother (who also have records in the table). One record per form. I have a Tab Control in the form, and in one of the tabs I have a subform (sfmSiblings) in which I wish to list...
12
19008
by: MLH | last post by:
I have created two forms: frmBrowseNegsMainform and frmBrowseNegsSubform. I put a subform control on the first of these. The SourceObject property for the subform control is, of course, frmBrowseNegsSubform. I would like to perform an ascending or descending sort on any of the 7 columns shown in datasheet view in the subform control. I've been unsuccessful. Is there something tricky about sorting in subform controls?
4
7013
by: Dave Boyd | last post by:
Hi, I have two very similar forms each with a subform. The main form gets a few fields from the user and passes this back to a query that the subform is bound to. The requery is done when the user enters the last qualifying field on the main form. In one case this works fine, the subform shows the data the user wants to update -- which means showing all the data put in previously (ie showing this via the requery and the continuous...
2
3644
by: Bill Agee | last post by:
I have a subform called PaymentDetails and would like to dynamically assign the recordsource after the form/subform is opened. The recordsource for Payment Details is "PaymentDetails_qry" which uses a function to filter the Invoice #. The invoiceID is not known until after the form is opened. After the InvoiceID is selected from a dropdown I then want to assign the recordsource ...
9
24599
by: robert d via AccessMonster.com | last post by:
I'm not sure why the following isn't working. The subform loads correctly, but no data is displayed. I'm certain that there is data and I have checked that the SQL statement does in fact return that data (checked by pasting the statement into a new Access Query in the database window). Me.FutureSubform.SourceObject = "FutureProjectionSubForm" Me.FutureSubform.Form.RecordSource = "SELECT * FROM " Me.FutureSubform.Form.Requery Is...
2
6250
by: shifty shaker | last post by:
I need to get at a subofmr's recordsource in code. I want to change the recordsource dynamically. I thought this would be straight forward..but I keep getting errors. On Event forms!Mainform!subform!recordsource = "somequery" End sub
1
3243
by: veteranwebdesign | last post by:
Hello, I have a main form. I want forms to open in a subform control box. What is the code for the option group to open the subforms in the control box. I didn't create subforms, I created regular forms, but will create subforms if that is needed for this to work. My main goal is when a user clicks on a menu item and comes to a main
0
8676
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8608
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9029
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8867
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6522
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.