Problem exporting forms with DoCmd.TransferDatabase from an accde file.

jacky Perpète 41 Reputation points
2023-09-15T08:02:45.37+00:00

Access 2021

Hello,

In a database, from a button on a form, I create another database and export a table and a form to this new database. This functionality is in VBA code.

In the accdb file everything works perfectly.

I then create an accde file from the accdb file.

If I run the accde file, I get an error message about exporting the form.

Error

The export of the table was carried out correctly.

Here is the VBA code:

Private Sub Commande0_Click()

Dim db As Database
Dim filePathDataBaseDestination As String
Const pathDataBaseDestination As String = "D:\Documents\Tempo"
Const nameDataBaseDestination As String = "NewDB.accdb"

filePathDataBaseDestination = pathDataBaseDestination & "\" & nameDataBaseDestination

'Check if we need to create the database
If Dir(filePathDataBaseDestination) = "" Then
	'Create the database
	Set db = DBEngine.Workspaces(0).CreateDatabase(filePathDataBaseDestination, dbLangGeneral)
	
	'Transfer the table
     DoCmd.TransferDatabase acExport, "Microsoft Access", filePathDataBaseDestination, acTable, "Table1", "TableNew", False
	
	'Transfer the form
     DoCmd.TransferDatabase acExport, "Microsoft Access", filePathDataBaseDestination, acForm, "Formulaire2", "Formulaire2", False
	
	db.Close
End If

End Sub
Access Development
Access Development
Access: A family of Microsoft relational database management systems designed for ease of use.Development: The process of researching, productizing, and refining new or existing technologies.
817 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. jacky Perpète 41 Reputation points
    2023-09-16T04:50:06.7133333+00:00

    Hello,

    I just found the info on:

    https://support.microsoft.com/en-au/office/export-a-database-object-to-another-access-database-4e2cd6dd-e482-441e-88b5-aa5319a428a6.

    If the file is in ACCDE format, the source object must be a table, query, or macro. Forms, reports and modules cannot be exported.

    Unfortunately, this restriction is not explained in the help for the DoCmd.TransferDatabase method.

    The error message does not give good information for this restriction.

    0 comments No comments