Access
Novice to see: How to change the table/form/Report ... Got a name.
Problem:
How to change the name of a table or other database object
Method One:
Change table name, call ADOX (test environment is ADOX2.7)
Function Test ()
Debug.Print Renametablename ("B", "Cxcd")
End Function
Function Renametablename (Stroldname As String, strNewName as String) as Boolean
On Error Resume Next
Dim tbl as ADOX. Table
Dim Cat as New ADOX. Catalog
Set Cat. ActiveConnection = CurrentProject.Connection
' Above this sentence currentproject.connection in VB to change to have open Connection object
For each tbl in cat. Tables
If tbl. Name = Stroldname Then tbl. Name = strNewName
Next
If err.number <> 0 Then
Renametablename = False
Else
Renametablename = True
End If
End Function
Method Two:
Please use Docmd.rename "new table name", actable, "original table name"
To complete
Please refer to help more
The following excerpt from access2000 Help
Rename method
The Rename method performs the Rename operation in Visual Basic.
Expression. Rename (NewName, ObjectType, Oldname)
expression Required. Returns an expression for the DoCmd object.
NewName Variant type, required. A string expression that represents the new name of the object to be renamed. This new name must conform to the object naming rules for Microsoft Access objects.
ObjectType AcObjectType, Optional. The type of object to rename.
AcObjectType can be one of the following AcObjectType constants:
acDataAccessPage
Acdefault Default
Acdiagram
Acform
Acfunction
Acmacro
Acmodule
Acquery
Acreport
acServerView
acStoredProcedure
Actable
Oldname Variant type, optional. A string expression that represents the valid object name for the type specified by the ObjectType parameter. If you execute Visual Basic code that contains the Rename method in a class library database, Microsoft Access first searches the class library database for objects with that name before you search in the current database.
Description
For more information about how this action and its parameters work, see the action topic.
If you leave the ObjectType and Oldname arguments blank (for the ObjectType parameter, assuming it is the default constant, that is, acdefault), Microsoft Access renames the object selected in the Database window. To select an object in the Database window, you can use the SelectObject action or the SelectObject method and set the parameter in the Database window to Yes (True).
If you leave the ObjectType and Oldname arguments blank, do not use commas after the NewName argument.
Example
The following example renames the "Employees" table.
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.