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: -
-
Private Sub Command6_Click()
-
-
SetFilter
-
-
End Sub
-
-
-
-
Sub SetFilter()
-
-
Dim LSQL As String
-
-
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"
-
-
TopSalesByMonthsubform.RecordSource = LSQL
-
-
End Sub
-
-
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?
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: -
-
Private Sub Command6_Click()
-
-
SetFilter
-
-
End Sub
-
-
-
-
Sub SetFilter()
-
-
Dim LSQL As String
-
-
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"
-
-
TopSalesByMonthsubform.RecordSource = LSQL
-
-
End Sub
-
-
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?
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.
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. -
TopSalesByMonthsubform.RecordSource = LSQL
-
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. -
Me!TopSalesByMonthsubform
-
or
-
Me.TopSalesByMonthsubform
-
2. Above expressions return Control object which does not have RecordSource property. You need to get Form property of the Control. -
Me.TopSalesByMonthsubform.Form.RecordSource=LSQL
-
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
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
Brilliant, cheers!
I knew I wasn't referencing properly!
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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...
|
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...
|
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?
|
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...
| |
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
...
|
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...
|
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
|
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
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |