Hi,
>i want to know how to have the number of grids on a form.
Is the question how many grids you can have on a form or how to find out how many grids you currently have? In the first case, you can have grids showing 32768 different cursors. You can have more grids than that, but they will show the same cursor. To find out how many grids you have you need to recursively go through all controls on the form and check the BaseClass property. Check out the Controls collection for the recursion.
>if there is one grid, i want to export to excel only fields that are on the grid.
Depends on how sophisticated you need this feature to be. The easiest case would be to create a SELECT statement using RecordSource for the FROM clause and all ControlSources for the field list. Then use COPY TO to copy this to Excel. You could also use automation or generate XML to keep formatting and data types. In addition you could evaluate the order, header and column width to persist the current layout. You could also evaluate the current index to keep the sort order. For generic solutions you additionally might have to deal with different recordsource types and columns that do not have a controlsource or use Dynamic properties extensively.
--
Christof