Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

Microsoft Excel Power in MS-Access

Introduction.

Sometimes, Microsoft Access users need report data exported to Excel for further analysis and custom work. In such cases, you can create a macro using the OutputTo command or the VBA DoCmd.OutputTo method to export data from a Table or Query and automatically open it in Excel.

The sample Macro command and parameter settings are illustrated in the image below:

The same action in Visual Basic Code is given below:

Function xPort2XL()
    DoCmd.OutputTo acTable, "Products", "MicrosoftExcelBiff8(*.xls)", "C:\My Documents\Products.xls", True, "", 0
End Function

Both can be run from a Command Button. Click on the Main Switch Board.

Imagine if users could perform all the tasks they normally do in Microsoft Excel—such as creating formulas, formatting cells, preparing charts, printing reports, and more—directly from within Microsoft Access. That would provide a completely different and seamless experience. They could even save a copy of their work as an independent Excel workbook outside Access whenever needed.

The Design Task.

Only a few things are involved to implement it in your Projects.

  1. Open a new Form in Design View in your Database.

  2. Expand the Detail Section of the Form large enough for the size of the Worksheet you would like to display on the Form.

  3. Display the Toolbox (View -> Toolbars -> Control Toolbox), if it is not visible.

  4. Select the Control Wizards Tool Button (the button with a magic wand icon) to activate it.

  5. Select the Unbound Object Frame Tool from the Toolbox.

  6. Draw a rectangle large enough to accommodate the size of the Worksheet you need. Leave about a quarter of an inch space on all four sides of the Form. A sample image is given below for reference:

    This action will display a list of Objects that can be inserted into the Unbound Object Frame.

  7. See that the Create New Radio Button is selected and Select Microsoft Excel Worksheet from the displayed Object Type List, and click the OK Command Button.

    An Excel Worksheet will be inserted into the Unbound Object Frame area on the Form. 

    If you look at the Menus and Toolbars above, you can see that all of them have been changed into Microsoft Excel Menus and Toolbars now. You can see the Formula Bar and the active Cell Address to the left of the Formula Bar. Type some expression in the Formula Bar to save it in the active cell if you want to try now.

    But we are now in the Design View of the Form. First, we must save the Form with an appropriate name and then open the Form in Normal View for use.

    Unlocking Worksheet for Normal Use

    Before saving the Form, we must change a few Property Values of the Unbound Object Frame (the housing frame of the Worksheet Object) that were drawn initially. The Unbound Object Frame will be in a Disabled and Locked state in the normal view of the Form. We must modify these properties to work with the Worksheet in the normal view of the Form.

  8. Click outside the Worksheet on the Detail Section of the Form to deactivate the Worksheet.

    The Unbound Object Frame with the Worksheet will be in a selected state (if it is not, click on it again to select it), showing the sizing controls on all four sides and corners. Now the Menus and Toolbars have changed back to MS-Access.

  9. Select View -> Properties to display the Property Sheet of the Unbound Object Frame and change the following Property Values as shown below:

    • Enabled = Yes

    • Locked = No

  10. Close the Property Sheet.

    NB: You may modify the look of your Form with a Title on the Header Section of the Form and change the Property settings of the Form to remove the Record Selector, Navigation Buttons,  Dividing Lines, etc. Add a Command Button at the Form Footer and attach a Macro to close the Form.

  11. Select Close from the File Menu and save the Form with the name XlWorkBook.

    Preparing Worksheet for Normal Operations.

  12. Open the XlWorkBook Form in Normal View.

    When you open the Form, the Unbound Object Frame will be in the selected state, showing the Excel Worksheet Grid and the sizing controls, as we saw earlier in Design View.

  13. Right-click somewhere on the Control to display the Shortcut Menu.

  14. Select Edit from the Worksheet Object Option displayed. You can double-click on the Unbound Object Frame to get the same result.

    The Worksheet becomes active now. Menus and Toolbars are now changed to Excel, and the Formula-Bar is showing up above the Form.

    A Few Issues with the Worksheet need correction.

    I understand that working with this worksheet may feel uncomfortable because only a limited area is visible, the scrollbars may not appear correctly, or the worksheet tabs are hidden. Don’t worry—these are all temporary issues that can be fixed quickly.

    Before addressing that, you might wonder how to bring data from an Access table or query into this worksheet. You cannot link a table from the same database directly, nor can you use Excel’s Import Data option via ODBC for this purpose—it’s either ineffective or not recommended for users.

    The simplest solution is to open the table or query in Datasheet View, select the rows, columns, or the entire dataset you need, copy it to the clipboard, and paste it directly into the worksheet.

  15. Minimize the xlWorkBook Form, and the Access Menu is back.

  16. Open a Table or Query in Datasheet View (this can be done through a macro for Users).

  17. Click on the left top corner of Rows and Columns to highlight the entire Table or Query contents (or select a few rows or Columns).

  18. Select Copy from the Edit Menu.

  19. Minimize the Datasheet View and Maximize the xlWorkBook Form.

  20. Click on the top left corner of the Worksheet area where you would like to paste the data.

  21. Select Paste from the Edit Menu. The copied contents will be pasted onto the Worksheet.

    You can close and reopen the Form, and all the changes you made earlier will be preserved and displayed.

    NB: The normal Excel Paste Special... Menu Options are not available here, but you can get them when the Excel Workbook is open in a different mode.

    You can work with the data as you will do in a worksheet, to add another Worksheet, write a formula, do calculations, create Charts, and so on. There are certain things that you cannot do here (in this state of the Form), like mark an area of the worksheet as Print Area, or do Page Setup changes, or Print Preview of the Worksheet. That doesn't mean that we cannot do these things at all.

    Worksheet EDIT or OPEN Mode

    These drawbacks can be solved by opening the Worksheet in a different Mode.

  22. Click on the Form's detail Section outside the Unbound Object Frame to deactivate the Worksheet.

  23. Right-click on the Unbound Object Frame and select Open (earlier we had selected Edit) from the Worksheet Object Menu.

The Worksheet will open in a standard Microsoft Excel window, allowing you to perform any special analysis. You can add additional worksheets, write formulas, create charts, and more.

You can select specific areas of the worksheet as a Print Area, adjust Page Setup, use Print Preview, or print the worksheet. All standard Paste Special options are available for use.

Any changes you make can be updated directly on the MS-Access Form by selecting the Update option from the File menu. There’s no need to locate the Excel file on your disk. If desired, you can also save a copy of the workbook as a regular Excel file using Save Copy As from the File menu.

Once your work is complete, select Close & Return to xlWorkBook: Form to return to the MS-Access Form, ensuring that all your changes are saved.

Isn't it something different to work with Excel from within MS-Access?

  1. Roundup Function of Excel in MS-Access
  2. Proper Function of Excel in Microsoft Access
  3. Appending Data from Excel to Access
  4. Writing Excel Data Directly into Access
  5. Printing MS-Access Report from Excel
  6. Copy-Paste Data From Excel to Access 2007
  7. Microsoft Excel-Power in MS-Access
  8. Rounding Function MROUND of Excel
  9. MS-Access Live Data in Excel
  10. Access Live Data in Excel- 2
  11. Opening an Excel Database Directly
  12. Create Excel, Word Files from Access
Share:

3 comments:

  1. Great site. A lot of useful information here. I’m sending it to some friends!

    ReplyDelete
  2. Heh I am actually the first comment to this incredible writing?!

    ReplyDelete
  3. If I had a penny for every time I came to www.msaccesstips.com! Superb post.

    ReplyDelete

Comments subject to moderation before publishing.

PRESENTATION: ACCESS USER GROUPS (EUROPE)

Translate

PageRank

Post Feed


Search

Popular Posts

Blog Archive

Powered by Blogger.

Labels

Forms Functions How Tos MS-Access Security Reports msaccess forms Animations msaccess animation Utilities msaccess controls Access and Internet MS-Access Scurity MS-Access and Internet Class Module External Links Queries Array msaccess reports Accesstips WithEvents msaccess tips Downloads Objects Menus and Toolbars Collection Object MsaccessLinks Process Controls Art Work Property msaccess How Tos Combo Boxes Dictionary Object ListView Control Query VBA msaccessQuery Calculation Event Graph Charts ImageList Control List Boxes TreeView Control Command Buttons Controls Data Emails and Alerts Form Custom Functions Custom Wizards DOS Commands Data Type Key Object Reference ms-access functions msaccess functions msaccess graphs msaccess reporttricks Command Button Report msaccess menus msaccessprocess security advanced Access Security Add Auto-Number Field Type Form Instances ImageList Item Macros Menus Nodes RaiseEvent Recordset Top Values Variables Wrapper Classes msaccess email progressmeter Access2007 Copy Excel Export Expression Fields Join Methods Microsoft Numbering System Records Security Split SubForm Table Tables Time Difference Utility WScript Workgroup database function msaccess wizards tutorial Access Emails and Alerts Access Fields Access How Tos Access Mail Merge Access2003 Accounting Year Action Animation Attachment Binary Numbers Bookmarks Budgeting ChDir Color Palette Common Controls Conditional Formatting Data Filtering Database Records Defining Pages Desktop Shortcuts Diagram Disk Dynamic Lookup Error Handler External Filter Formatting Groups Hexadecimal Numbers Import Labels List Logo Macro Mail Merge Main Form Memo Message Box Monitoring Octal Numbers Operating System Paste Primary-Key Product Rank Reading Remove Rich Text Sequence SetFocus Summary Tab-Page Union Query User Users Water-Mark Word automatically commands hyperlinks iSeries Date iif ms-access msaccess msaccess alerts pdf files reference restore switch text toolbar updating upload vba code