Table and crosstab query on a form - MS Access - ms-access

I have a form is Access that needs to edit data in a table, but also display corresponding info that is in a crosstab query. I know I cant edit the crosstab query, but I need to be able to edit the table. Whenever a make a query that includes my table and the data from the crosstab query, it makes the whole thing locked so I cannot edit. I have already set the recordset type to dynaset inconsistent updates.
Thanks!

Related

Update Table created from a query with same query

I have a power BI report, which gets it's data from table in a MC Access database.
I have to update these tables in Access often, to get up to date data in my report. But I can't figure out how MS Access query, can update all rows with the same query it was made from. That includes removing rows from the old table, if they do not exist in the new query.
I can delete the table and then use the query again. But power BI loses it's reference, and I have to create the graphs again. I'd like to keep the Access table, but get the content replaced the content of the next query run.

Microsoft Access: create subdatasheet with SQL command?

Microsoft Access supports "subdatasheets"
Is it possible to create this type of table from a SQL command? Or does one have to manually point and click to do it.
SQL commands can run scripts/manipulate data and organize it. It's a declarative language. What you're referring to is part of Access' UI features/capabilities.
Your subdatasheet link shows an Orders table with a 1:M relationship to an Order Details table. One Order record with many details about that Order.
The reference you linked shows you how to set this up; it doesn't take any SQL or even VBA to do this. This is a way to view data and it's correlated data from another table in a Datasheet view.

Refreshing Access passthrough query

I have a passthrough query to pull my "Active Members" from an Oracle database via an ODBC passthrough query. It works great, I can link to members retrieved by the query just like I would an Access table.
My question is, will this passthrough query automatically refresh itself each time I reference it? Or should I specify the update using VBA code? Essentially, each time a user searches for a member, I need my pass through query re-run.
No, there's no auto-refresh of pass-through queries, they're just queries stored in another db's syntax.
What I usually do is create a macro deleting rows from the existing table and running the pass-through query. If the macro introduces too much overhead, however, you could also code the steps in a function with VBA.

Access Continuous Form with Linked Table - How to Avoid Hitting Database Server for Every Row in Form?

I'm migrating the data from an Access database to SQL Server via the SQL Server Migration Assistant (SSMA). The Access application will continue to be used with the local tables converted to linked tables.
One continuous form hangs for 15 - 30 seconds when it's loading. It displays approximately 2000 records. When I looked in SQL Server Profiler to see what it was doing, it was making a separate call to the backend database for each record in the form. So the delay when the form opens is caused by the 2000-odd separate calls to the database.
This is amazingly inefficient. Is there any way to get Access to make a single call to the backend database and retrieve all the records at once?
I don't know if this is relevant but the Record Source for the form is a view in the SQL Server backend database, which is linked to via an Access linked table (so, hopefully, Access just sees it as a table, not a view). I needed an Instead Of trigger on the view in SQL Server, and a unique index on the linked table in Access, to allow the records to be updated via the form.
If the act of opening that continuous form really does generate ~2000 separate SQL queries (one for every row in the view) then that is unusual behaviour for Access interacting with a SQL Server linked "table". Under normal circumstances what takes place is:
Access submits a single query to return all of the Primary Key values for all rows in the table/view. This query may be filtered and/or sorted by other columns based on the Filter and Order By properties of the form. This gives Access a list of the key values for every row that might be displayed in the form, in the order in which they will appear.
Access then creates a SQL prepared statement using sp_prepexec to retrieve entire rows from the table/view ten (10) rows at a time. The first call looks something like this...
declare #p1 int
set #p1=4
exec sp_prepexec #p1 output,N'#P1 int,#P2 int,#P3 int,#P4 int,#P5 int,#P6 int,#P7 int,#P8 int,#P9 int,#P10 int',N'SELECT "ID","AgentName" FROM "dbo"."myTbl" WHERE "ID" = #P1 OR "ID" = #P2 OR "ID" = #P3 OR "ID" = #P4 OR "ID" = #P5 OR "ID" = #P6 OR "ID" = #P7 OR "ID" = #P8 OR "ID" = #P9 OR "ID" = #P10',358,359,360,361,362,363,364,365,366,367
select #p1
...and each subsequent call uses sp_execute, something like this
exec sp_execute 4,368,369,370,371,372,373,374,375,376,377
Access repeats those calls until it has retrieved enough rows to fill the current page of continuous forms. It then displays those forms immediately.
Once the forms have been displayed, Access will "pre-fetch" a couple of more batches of rows (10 rows each) in anticipation of the user hitting PgDn or starting to scroll down.
If the user clicks the "Last Record" button in the record navigator, Access again uses sp_prepexec and sp_execute to request enough 10-row batches to fill the last page of the form, and possibly pre-fetch another couple of batches in case the user decides to hit PgUp or start scrolling up.
So in your case if Access really is causing SQL Server to run individual queries for every single row in the view then there may be something particular about your SQL View that is causing it. You could test that by creating an Access linked table to a single SQL Table or a simple one-table SQL View, then use SQL Server Profiler to check if opening that linked table causes the same behaviour.
Turned out the problem was two aggregate fields. One field's Control Source was =Count(ID) and the other field's Control Source was =Sum(Total_Qty).
Clearing the control sources of those two fields allowed the form to open quickly. SQL Server Profiler shows it calling sp_execute, as Gord Thompson described, to retrieve seven batches of 10 rows at a time. Much quicker than making 2000 calls to retrieve one row at a time.
I've come across the same problem again but this time with a different cause. I'm including it here for completeness, to help anyone in a similar situation:
This time the underlying query was hanging and SQL Server Profiler showed the same behaviour as before, with Access making separate calls to the SQL Server database to bring back one record at a time, for every record in the query.
The cause turned out to be the ORDER BY clause in the query. I guess Access had to pull back all records in the linked table from SQL Server before being able to order them. Makes sense when I think of it. Although I don't know why Access doesn't just pull all records through at once, instead of getting the records one at a time.
I would try setting the Recordset Type to Snapshot (on the Data tab of the Form's property sheet and/or the property sheet of the query you are using for the form source)

ACCESS 2010 / SQL: How do you copy a row which has an attachment field?

I want to run a SQL query to copy a row from my table to either the same table or another table.
Whichever method I use, I end up with a message telling me something similar to "You can't run an INSERT INTO query if it contains a multi-value field" (translated from french)
I tried using SELECT * INTO, but the result is the same.
My table is about reports, which can have a revision (hence the row copy), and they can have an attachment like for ex. a pdf file.
so, how do you / can you copy a row which has an attachment field ?
Thanks
I do not have Access 2010 to hand at the moment, but you will find that attachments are stored in hidden system tables as single records and that you need to use that table to copy multiple records, unless you wish to use VBA.
More info: http://office.microsoft.com/en-us/access-help/guide-to-multivalued-fields-HA001233722.aspx?pid=CH100645681033
http://msdn.microsoft.com/en-us/library/bb258184.aspx