I like to use an unbound subform to display the result of an crosstab query. However following code
Me.subFormForecastSummary.Form.RecordSource = "SELECT ....."
results in this error message: "The expression you entered refers to an object that is closed or doesn't exist".
When I use the Source Object in the form designer and specify the select statement, then the code above works fine and I am able to set the property RecordSource.
The issue I am facing is that the select statement is based on a crosstab query and can contain a different number of columns (in my case weeks) depending on the master record. The issue I am facing is that the datasheet only displays the columns as per the original query specified in SourceObject (the data itself is refreshed though). Does anyone know how I can force the columns to be refreshed as well or how I can get overcome the error message?
Thanks
Thanks for the responses thus far. Based on the comments and further research I have decided on following solution:
Created a dummy query returning 1 record with the maximum number of columns. I have named them 001 trough to 100
Still created a subform and bound it to the dummy query
In VBA I then change the recordsource at runtime as required
Also in VBA rename the captions as required
You would think there should be a more elegant solution, but this works for me
Related
I have an Access application that has been running for years now. It's a payroll system. There's a query (let's call it Query3) that pulls data from 2 crosstab queries. Everything worked fine until when I introduced a parameter in the crosstab queries. The parameter refers to a date on a form. Now I can't create a report with Query3 as its record source. When I use Report Wizard and I select Query3 as its record source the field names are not displayed. I have a sub that programmatically creates a report based on Query3 but now with the parameter this fails too. I'm really stumped. Is there any workaround? Thanks in advance for your help.
Are you using the Forms!MyForms!MyControl syntax as the parameter in the Crosstab subs? The problem seems to be related to Access not finding the control .
One thing I have done in the past is, if possible, is to remove the crosstab parameters and instead set the SQL of the crosstabs before running the report. So for example:
CurrentDB.QueryDefs("CrossTabSubName").SQL - "SELECT * FROM TABLE WHERE MyParam = 'A'"
If you have a button or something that launches the report, this may be an convenient place to do this. If the parameter is on the same form (i.e. a report filter), then this approach is simple to implement. In this example, the value of 'A' is a control on the form that allows th user to filter the report.
I spent half day trying to figure out why appears an error messagebox
Could not find field 'TransactionTypeID'
in my
database. If you open Form1, then apply any filter on column TransactionTypeID using header (for instance, uncheck Blanks) and then try to open sorting/filtering for second column, appears error message.
Error disappears if I convert combobox to text box or remove from form select table Tenants1. I use Access 2010 32 bit. In this example I simplified tables as much as possible, database created from scratch, data imported, compact/repair doesn't help.
Do you have any ideas?
I found the problem. The built-in datasheet form filtering works in a wrong way if tables joined this way:
SELECT VouchersMain1.VDate, VouchersMain1.TransactionTypeID
FROM Tenant1 INNER JOIN VouchersMain1 ON Tenant1.TenantID = VouchersMain1.TenantID;
If I reverse tables join direction, built-in filtering works fine:
SELECT VouchersMain1.VDate, VouchersMain1.TransactionTypeID
FROM VouchersMain1 INNER JOIN Tenant1 ON VouchersMain1.TenantID = Tenant1.TenantID;
Looks like this is another Access bug.
Also, thanks #Munsterlander, problem disappears if form's recordsource replaced by saved query instead of SELECT
Try referencing your field as Forms!FORMNAME!CONTROLNAME. I assume, based off what you wrote, you are trying to filter a query based on what is selected in the combobox.
Delete the table Tenants1 from your form RecordSource (this table is not necessary and do not exposes fields in the resulting query).
You would also note that your recordsource is set (by Access) ReadOnly (bad design, no join defined). Try to add a couple of Records in the Tenant1 table, say it David and Nathan.
You will find that now your query will output 6 records (and not 2), because the query (with no joins) list one row for all records of table Tenant1 (3) and one row for each record of table VouchersMain1 (2), giving a total of 2*3=6 rows.
I have a form with a subform, and I want the subform record source that populates the subform to change depending on the inputs on some combo boxes in the main form.
Using VBA, I have built a function that generates the SQL statement I want to populate the subform with. I know this works because I have tested it with the msgbox and it gives me the SQL statement I want. The sql statement uses an aggregate function so the resulting table has a different structure than the table it is querying from.
The code I use to change the subform record source is:
me![subformname subform].form.recordsource=myfunction()
This has worked for me in the past, but does not work here, I simply get "#Name?" in the subform on my form.
When I open the subform separately I get "#Name?" but when I open the Recourd Source and run the query from the record source I get a value so I am confused.
Any ideas?
Try setting up two subforms - one for each format that you need - and when you swap the underlying recordsets also swap or hide/unhide the relevant subform. Then you can set the controlsource for the relevant controls to the fields that are actually available in the current recordset.
I got it to work by changing the structure of the subform I was changing so that the structure stayed the same when I altered the recordsource. The lesson is, you can change the recordsource in VBA, but you can't change the structure of the subform.
My problem occurred because I used an alias in my subform record source SELECT query. When I replaced the alias table names with the actual database table names in my VBA code, the .recordsource = strSQL01 statement worked and the data appeared in my subform.
I am at a loss as to why I am getting a run time error message saying that the record set is not updatable for a simple table which I created and sourced in a new form not dependent on anything else. Is it possible the database settings have somehow changed causing me this strange issue. How is this possible?
Some more details would be needed.
Anyway, how are you trying to modify the recordset? Via VBA?
I suggest some things you can try:
Open form properties --> Data tab and check that Allow modifications is set to Yes as far as Allow Additions and so on
1) You are trying to access the record before updating
2) In VBA you didn't invoke the .Edit method before trying to modify the record.
3) The form has a query as record source and the query is not updatable
The case 3) is the most complex of the three. It can be due, for example, to:
- Presence of total clauses like GROUP BY, COUNT, SUM that means that a record represents a set
- A calculated field that can't be updated
- Lack of permission to modify the table / query
I have an Access 2007 report which has a table as a data source. I have a few columns of data that directly pull data from the table in a summarized way (using report groups) and the last column is the total of the first 6 columns. Simple enough.
Now the expression that calculates the sum of those 6 columns sometimes returns #NAME? and sometimes does not. I have more than triple-checked for any error, typo, whatever.
There is no space in front of my expression;
The expression does start with an =;
The references to columns in the table are all valid;
No control has a name even remotely similar to any column in the source table;
I have tried generating the expression using the expression builder;
There is no conditional formatting tied to any control;
There is no VBA code used at all in generating the report.
Also, sometimes if I copy the one of the boxes with #NAME?, delete it and paste it back then all the #NAME? errors disappear. Then I save and reopen the report and the errors are back.
I'm out of ideas for this. I can't post screenshots or distribute the file due to its nature.
Thanks !
I had similar problems...The solution was that I have used unicode characters in Names. For example a Text Box with the control source "dataščž" had the Name "datačšž". This was working in previous versions of Access, but not anymore. Changing the Name "datacsz" solved the problem.