Solved

MS Access and DataGrid

Posted on 2004-04-08
11
5,956 Views
Last Modified: 2012-08-13
Hi,

I have an access form that I would like to add a data grid to. Everything I have read says "Don't Do It!"
I know that I can show an access form in the datasheet mode and that will display like a grid. However, I can't find a way to make the datasheet appear in a cross tab format.

For example, my table contains the following fields: SKU, STORE, QTY when pulling data for my form I just select all records from the table and assign the correct values to the txt boxes. The datasheet view then appears and looks like this:

SKU:    STORE:   QTY:
11111       335       10
11111       336       11
11111       337         9
22222       335       22
22222       336       19
22222       337       10
33333       335       10
33333       336       15
33333       337        0

But what I would like is this:

SKU:       STORE 335:   STORE 336:    STORE 337:
11111            10                  11                  9
22222            22                  19                10
33333            10                  15                  0

Any suggestions on making this happen? I have been able to make this work using a datagrid in VB but in Access I'm at a loss so any help would be appreciated.

Thanks,
Jessica
0
Comment
Question by:jessib
11 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 10785603
Hello jessib,

Sounds like the built in Crosstab query to me.
Start a new query and follow the crosstab query wizard.

Pete
0
 
LVL 11

Expert Comment

by:phileoca
ID: 10785628
Greeting jessica,
create a query, and put this in SQL, this will create what you want.   u can then call the query from a REPORT or form..  i suggest the REPORT:

TRANSFORM Sum(yourtable.QTY) AS SumOfQTY
SELECT yourtable.SKU
FROM yourtable
GROUP BY yourtable.SKU
PIVOT yourtable.Store;

''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Jessica,
Replace 'YourTable' with yourtable name.
Sku = sku field
Store = store field
QTY = QTY field

KT
0
 

Author Comment

by:jessib
ID: 10785698
Thanks for both replies, I see I forgot to mention one thing in my first post. The reason I am wanting a grid format is so that my users can modify the QTY field. I have been able to get a crosstab query to appear as I want, but of course since it is a query I'm not able to modify any fields.

Any suggestions?
0
 
LVL 11

Expert Comment

by:phileoca
ID: 10785796
just curious, what was your CODE in VB.
0
 

Author Comment

by:jessib
ID: 10785838
I didn't use this exact setup in vb but one similar...I was able to make the datagrid work using an ADO datasource:

doing so...

selected data from table
set the ado.recordsource = strSelect
           ado.refresh

then set the datagrid's datasource to the ADO

I tried something similar in access and was unable to get it work
0
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
LVL 12

Expert Comment

by:nexusnation
ID: 10786087
Jessica, just a quick comment:

< but of course since it is a query I'm not able to modify any fields. >

Well, that isn't completely true. It all depends on the query. Crosstabs, usually (if not always) no. Some SELECT queries yes, while others no. I don't know the exact rules, but that's because If I was shown an SQL statement, I'd be able to tell if you can edit it or not. Anyways... ;)

Just popping in.

Andrew
0
 

Author Comment

by:jessib
ID: 10786153
Andrew,

Thanks.  This example from Phileoca gives me a crosstab which is the format I want it just doesn't allow editing of the QTY field.

TRANSFORM Sum(yourtable.QTY) AS SumOfQTY
SELECT yourtable.SKU
FROM yourtable
GROUP BY yourtable.SKU
PIVOT yourtable.Store;

You said that crosstabs, usually don't allow modifications, can you give me an example of when a crosstab may allow a modification?

Jessica
0
 
LVL 7

Accepted Solution

by:
donpricejr earned 500 total points
ID: 10786649
Here are the rules on updating query's in a Jet source:
-----------------------------
When can I update data from a query?
In some cases, you can edit data in query Datasheet view to change the data in the underlying table. In other cases, you can't. The following information shows whether a query's results can be updated, and if not, whether there is an alternative.

Data is updatable

You can update a query or query field in the following cases:

A query based on one table
A query based on tables with a one-to-one relationship
The query's results contain a Memo, Hyperlink, or OLE Object
Data is updatable under certain conditions

If a query is based on tables with a one-to-many relationship, you might not be able to edit the data for the following query fields.

Query field Solution
Join field from the "one" side Enable cascading updates between the two tables.
New records, if the "many" side join field doesn't appear in the datasheet Add the join field from the "many" side to your query to allow adding new records.
Join field from the "many" side, after you've updated data on the "one" side Save the record; then you'll be able to make changes to the "many" side join field.
Blank field from the table on the "one" side of a one-to-many relationship where an outer join exists Enter values in fields from the table on the "many" side, but only if the joined field from the "one" side contains a value for that record.
New records, if entire unique key of ODBC table isn't output Select all primary key fields of ODBC tables to allow inserts into them.

Data can be deleted but not updated

Query or query field Solution
Query (or underlying table) for which Update Data permission isn't granted To modify data, permissions must be assigned.
Query (or underlying table) for which Delete Data permission isn't granted To delete data, permissions must be assigned.  

Data can't be updated

Query or query field Solution
Query based on three or more tables in which there is a many-to-one-to-many relationship Though you can't update the data in the query directly, you can update the data in a form or data access page based on the query if the form's RecordsetType property is set to Dynaset (Inconsistent Updates).
Crosstab query  None
SQL pass-through query  None
Query that calculates a sum, average, count or other type of total on the values in a field, or an update query that references a field in the Update To row from either a crosstab query, select query, or subquery that contains totals or aggregate functions By using a domain aggregate function in the Update To row of an update query, you can reference fields from either a crosstab query, select query, or subquery that contains totals or aggregate functions.  
Union query  None
Query whose UniqueValues property is set to Yes  None
Query that includes a linked ODBC table with no unique index, or a Paradox table without a primary key  None
Query that includes more than one table or query, and the tables or queries aren't joined by a join line in Design view You must join the tables properly in order to update them.
Calculated field  None
Field is read-only; the database was opened as read-only or is located on a read-only drive  None
Field in record that has been deleted or locked by another user A locked record should be updatable as soon as it is unlocked.
-------------------------

-Don
0
 

Author Comment

by:jessib
ID: 10805884
Thanks to all who answered, I was able to find a solution to my problem. Instead of using the data grid I have been able to place a msflexgrid on my form and create the layout that I wanted. I referenced MSKB Article 241355 to get this to work.
0
 

Expert Comment

by:madhavprabhu
ID: 11654562
Hello Jessica,
I have the same scenerio as yours, i.e. want an editable datagrid for displaying crosstab query, and on edit of field update the underlying table.
As you have suggested, i refered the MSKB Article 241355, but how did you tackle the events of mouse move, enter cell, leave cell and the dynamic moving of textbox.
This is because, ms acces forms does not support this events.
Kindly reply at the earliest,
Regards,
Madhav
0
 

Expert Comment

by:heddie
ID: 12321194
phileoca,

with regards to ur response..

TRANSFORM Sum(yourtable.QTY) AS SumOfQTY
SELECT yourtable.SKU
FROM yourtable
GROUP BY yourtable.SKU
PIVOT yourtable.Store;

''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Jessica,
Replace 'YourTable' with yourtable name.
Sku = sku field
Store = store field
QTY = QTY field


how would u do this if I wanted a query to display the the results in a similar pattern.. meaning the query has the field I wanted to display as oppose to a table.

rgds,

ps... can u show me how I can get a parameter prompt for the query.

tks,
h'eddie


0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now