Adding References in VBA for Microsoft Access

D Brown 0 Reputation points
2025-03-03T15:18:24.07+00:00

How can the following references be added to the VBA references list in Microsoft Access purchased with a Microsoft 365 subscription?

  1. Microsoft Forms 2.0 Object Library for MSForms.DataObject (clipboard handling).
  2. Microsoft Scripting Runtime for FileSystemObject.

What steps should be taken to utilize these references in VBA code?

Microsoft 365 and Office | Development | Microsoft 365 Developer Program
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Marcoz Zampieri 65 Reputation points
    2025-03-03T15:28:34.58+00:00

    hi, D Brown, To add references like Microsoft Forms 2.0 Object Library (for MSForms.DataObject) and Microsoft Scripting Runtime (for FileSystemObject) in Microsoft Access purchased with a Microsoft 365 subscription, follow these steps:Step-by-Step Guide:

    Open Microsoft Access:

    • Start Microsoft Access and open the database where you want to add the references.

    Open the VBA Editor:

      - Press `Alt + F11` to open the **Visual Basic for Applications (VBA)** editor.
      
      **Access the References Dialog**:
      
         - In the VBA editor, go to the **Tools** menu at the top.
         
            - Click on **References** from the dropdown.
            
            **Add Microsoft Forms 2.0 Object Library**:
            
               - In the **References** dialog box, look for **Microsoft Forms 2.0 Object Library**.
               
                     - If you cannot find it in the list, you may need to browse for it.
                     
                           - Click on the **Browse** button at the bottom of the References dialog.
                           
                                 - Navigate to the path of the **FM20.DLL** file, which is typically located in one of these directories:
                                 
                                          - `C:\Windows\System32\FM20.DLL` (for 32-bit Windows)
                                          
                                                   - `C:\Windows\SysWow64\FM20.DLL` (for 64-bit Windows)
                                                   
                                                         - After selecting the **FM20.DLL** file, click **Open** to add the library.
                                                         
                                                         **Add Microsoft Scripting Runtime**:
                                                         
                                                            - In the **References** dialog, scroll down and check the box next to **Microsoft Scripting Runtime**.
                                                            
                                                               - This library provides access to **FileSystemObject** and other scripting functions.
                                                               
                                                               **Confirm and Close**:
                                                               
                                                                  - After selecting the desired references (Microsoft Forms 2.0 and Microsoft Scripting Runtime), click **OK** to close the References dialog box.
                                                                  
                                                                  **Write VBA Code Using the References**:
                                                                  
                                                                     - Now you can use the **MSForms.DataObject** (from **Microsoft Forms 2.0 Object Library**) and **FileSystemObject** (from **Microsoft Scripting Runtime**) in your VBA code. For example:
                                                                     
                                                                           - For clipboard handling with `MSForms.DataObject`:
                                                                           
                                                                           ```vba
                                                                           vba
                                                                           Copia
                                                                           Dim objData As MSForms.DataObject
    

    Set objData = New MSForms.DataObject objData.SetText "Hello, Clipboard!" objData.PutInClipboard ```

                                                                                 - For working with files using `FileSystemObject`:
                                                                                 
                                                                                 ```vba
                                                                                 vb
                                                                                 Copia
                                                                                 Dim fso As FileSystemObject
    

    Set fso = New FileSystemObject If fso.FileExists("C:\path\to\file.txt") Then ' Do something with the file End If ```

                                                                                 **Save Your Work**:
                                                                                 
                                                                                    - After writing your code, save the VBA project and close the VBA editor by pressing `Alt + Q`.
                                                                                    
    

    Notes:

    • If you encounter issues finding Microsoft Forms 2.0 Object Library or if it's not available, it might be due to restrictions or differences in the versions of Microsoft Office. In some cases, you may have to manually install or register FM20.DLL.
    • The Microsoft Forms 2.0 Object Library is generally available in older versions of Microsoft Office (like Office 2010 or earlier), but its availability may vary in newer versions or installations from Microsoft 365.To add references like Microsoft Forms 2.0 Object Library (for MSForms.DataObject) and Microsoft Scripting Runtime (for FileSystemObject) in Microsoft Access purchased with a Microsoft 365 subscription, follow these steps: Step-by-Step Guide:
      1. Open Microsoft Access:
        • Start Microsoft Access and open the database where you want to add the references.
      2. Open the VBA Editor:
        • Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.
      3. Access the References Dialog:
        • In the VBA editor, go to the Tools menu at the top.
        • Click on References from the dropdown.
      4. Add Microsoft Forms 2.0 Object Library:
        • In the References dialog box, look for Microsoft Forms 2.0 Object Library.
        • If you cannot find it in the list, you may need to browse for it.
        • Click on the Browse button at the bottom of the References dialog.
        • Navigate to the path of the FM20.DLL file, which is typically located in one of these directories:
          • C:\Windows\System32\FM20.DLL (for 32-bit Windows)
          • C:\Windows\SysWow64\FM20.DLL (for 64-bit Windows)
        • After selecting the FM20.DLL file, click Open to add the library.
      1. Add Microsoft Scripting Runtime:
        • In the References dialog, scroll down and check the box next to Microsoft Scripting Runtime.
        • This library provides access to FileSystemObject and other scripting functions.
      2. Confirm and Close:
        • After selecting the desired references (Microsoft Forms 2.0 and Microsoft Scripting Runtime), click OK to close the References dialog box.
      3. Write VBA Code Using the References:
        • Now you can use the MSForms.DataObject (from Microsoft Forms 2.0 Object Library) and FileSystemObject (from Microsoft Scripting Runtime) in your VBA code. For example:
        • For clipboard handling with MSForms.DataObject:
                  vba
                  Copia
                  Dim objData As MSForms.DataObject
          

    Set objData = New MSForms.DataObject objData.SetText "Hello, Clipboard!" objData.PutInClipboard ```

      - For working with files using `FileSystemObject`:
      
        ```vba
        vb
        Copia
        Dim fso As FileSystemObject
    

    Set fso = New FileSystemObject If fso.FileExists("C:\path\to\file.txt") Then ' Do something with the file End If ```

    1. Save Your Work:
      • After writing your code, save the VBA project and close the VBA editor by pressing Alt + Q.

    Notes:

    • If you encounter issues finding Microsoft Forms 2.0 Object Library or if it's not available, it might be due to restrictions or differences in the versions of Microsoft Office. In some cases, you may have to manually install or register FM20.DLL.
    • The Microsoft Forms 2.0 Object Library is generally available in older versions of Microsoft Office (like Office 2010 or earlier), but its availability may vary in newer versions or installations from Microsoft 365.

    I hope I have been of help

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.