ACC2002: Files That Were Not Created by Data Source Control Can Be Overwritten (295819)



The information in this article applies to:

  • Microsoft Access 2002

This article was previously published under Q295819
Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

SYMPTOMS

When you use the Data Source Control in Microsoft Access to create a file, the control overwrites existing files created by other programs.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

The "BeforeOverwrite Event" topic in the Help system for the Microsoft Script Editor in Access contains the following note:

Note: Files that were not created by the Data Source Control will not be overwritten.

When you use the Data Source Control to create a file within a folder, the control should not overwrite an existing file created by another program, even after you instruct the BeforeOverwrite event to continue. However, the file created by another program is overwritten.

Steps to Reproduce the Behavior

  1. Start Notepad, and then type or paste the following text:
     <?xml version="1.0"?>
     <Schema>
      <Tables>
       <Table1>
        <ID>1</ID>
        <Name>Microsoft</Name>
        <Phone>(425)555-1212</Phone>
       </Table1>
      </Tables>
     </Schema>
    					
  2. Save the file as C:\Test\File.xml.
  3. On the same computer, open the sample database Northwind.mdb.
  4. On the Insert menu, click Page.
  5. In the New Data Access Page dialog box, click AutoPage: Columnar, click the arrow in the Choose the table or query where the object's data comes from box, click Shippers in the drop-down list, and then click OK.
  6. When the data access page has been created, click Design View on the View menu.
  7. Click the Command Button tool in the toolbox, and then click within the Header: Shippers section. If the Command Button Wizard starts, click Cancel.
  8. On the Tools menu, point to Macro, and then click Microsoft Script Editor.
  9. Click the arrow in the Object box, and then click Command0 in the drop-down list. Click the arrow in the Event box, and then click onclick in the drop-down list.
  10. Modify the script as follows:
    <SCRIPT event=onclick for=Command0 language=vbscript>
     <!--
      MSODSC.XMLLocation = MSODSC.Constants.dscXMLDataFile
      MSODSC.XMLDataTarget = "C:\Test\File.xml"
      MSODSC.ExportXML
     -->
    </SCRIPT>
    					
  11. Click the arrow in the Object box, and then click MSODSC in the drop-down list. Click the arrow in the Event box, and then click BeforeOverwrite in the drop-down list.
  12. Modify the script as follows, and make sure to add the objDSCEventInfo within the parentheses of this event:
    <SCRIPT event=BeforeOverwrite(objDSCEventInfo) for=MSODSC language=vbscript>
     <!--
      objDSCEventInfo.DisplayAlert = True
     -->
    </SCRIPT>
    					
  13. On the File menu, click Save. Save the page as Page1.htm.
  14. On the File menu, click Exit to return to Microsoft Access.
  15. On the View menu, click Page View.
  16. Click the command button, and then click Yes when you are prompted to continue.
  17. Start Notepad, and then open C:\Test\File.xml.
Note that the original Notepad file has been overwritten. The same behavior would occur if the Notepad file had a .txt extension and the XMLDataTarget code above also specified a .txt extension. In other words, the file name is not important. If you had specified "C:\Autoexec.bat" in the XMLDataTarget code above, the Autoexec.bat file would have been overwritten, even though the file was not created by using the Data Source Control.

REFERENCES

For more information about the BeforeOverwrite event of the data source control, click Microsoft Script Editor Help on the Help menu, type beforeoverwrite event in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

Modification Type:MajorLast Reviewed:11/5/2003
Keywords:kbbug kbDAPScript kbdocerr kbnofix KB295819