Restore the method for deleting a table from the Access Database

Source: Internet
Author: User

Restore the method for deleting a table from the Access Database

Note: The sample code in this article uses Microsoft Data to access objects. To run the code properly, you must reference the Microsoft DAO 3.6 Object Library. Yes. Click the Visual Basic Editor in the tool menu to reference and ensure that the check box of the Microsoft DAO 3.6 Object Library is selected.

1. Open the database in Microsoft Access.

2. In the database window, click object, module, and then click New.

3. type or paste the following code. You can only create a module:

Copy the Code as follows:

Function RecoverDeletedTable ()

On Error GoTo ExitHere

'* Declarations *

Dim db As DAO. Database

Dim strTableName As String

Dim strSQL As String

Dim intCount As Integer

Dim blnRestored As Boolean

'* Init *

Set db = CurrentDb ()

'* Procedure *

For intCount = 0 To db. TableDefs. Count-1

StrTableName = db. TableDefs (intCount). Name

If Left (strTableName, 4) = "~ Tmp "Then

StrSQL = "select distinctrow [" & strTableName & "]. * INTO" & Mid (strTableName, 5) & "FROM [" & strTableName & "];"

DoCmd. SetWarnings False

DoCmd. RunSQL strSQL

MsgBox "A deleted table has been restored, using the name'" & Mid (strTableName, 5) & "'", vbOKOnly, "Restored"

BlnRestored = True

End If

Next intCount

If blnRestored = False Then

MsgBox "No recoverable tables found", vbOKOnly

End If

'* EXIT/ERROR *

ExitHere:

DoCmd. SetWarnings True

Set db = Nothing

Exit Function

ErrorHandler:

MsgBox Err. Description

Resume ExitHere

End Function

4. On the Debug menu, click compile database name.

5. Save it as the RecoverTable module. To test this function, create two tables, Add rows, and delete the two tables.

6. In the real-time window, type the following line and press ENTER:

RecoverDeletedTable

Note: For more exciting tutorials, please follow the help houseDesign tutorialTopic,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.