473,386 Members | 1,962 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Subform Recordsource Nightmare

56
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 TopSalesByMonthsubform.RecordSource = LSQL but I can't see what. Its copied direct from past examples too.

Can anyone help?
Aug 8 '07 #1
6 2652
FishVal
2,653 Expert 2GB
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 TopSalesByMonthsubform.RecordSource = 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
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 Expert 2GB
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.RecordSource 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
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 Expert 2GB
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.RecordSource
Aug 9 '07 #6
Widge
56
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
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...
0
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...
25
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...
12
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,...
4
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...
2
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...
9
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...
2
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 ...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.