1

I have created and manipulated an external database from the existing tables in my current database.

The matter is that I necessarily have to manipulate "Description" property in the new database fields.

When I try to retrieve "Description" property from cereated external database, response is that "Description" isn't a property (Error 3270, "property not found")

How could I do it?

I tried the following code:

Sub Actualizacomentarios()

Dim dbFinal As DAO.Database

Dim tbl As DAO.TableDef
Dim fld As DAO.Field

Dim tblFinal As DAO.TableDef
Dim fldFinal As DAO.Field
Dim prpFinal As DAO.Property
Set dbFinal = DBEngine.OpenDatabase("D:\Dropbox\Expedientes JLE nueva epoca activos\17002 - Fermin Torres. Programa\NuevoFoasat.accdb")

For Each tbl In CurrentDb.TableDefs

    If InStr(tbl.Name, "JLE_") > 0 Then

        For Each fld In tbl.Fields

            Set tblFinal = dbFinal.TableDefs(tbl.Name)
            Set fldFinal = tblFinal.Fields(fld.Name)

            fldFinal.Properties("Description") = fld.Properties("Description") 'HERE OCCURS ERROR

        Next fld

    End If

Next tbl

dbFinal.Close
Set dbFinal = Nothing
braX
  • 11,506
  • 5
  • 20
  • 33
Javier
  • 189
  • 3
  • 16
  • 1
    ["Description" is a user-created property, so you must create it before you can give it a value.](https://stackoverflow.com/a/3522234/77335) – HansUp May 27 '20 at 18:48
  • Thanks, @HansUp, I have rewritten the code with your idea. See it if you want – Javier May 27 '20 at 18:49

1 Answers1

1

Rewritten and working . Thanks to @HansUp

Sub Actualizacomentarios()

Dim dbFinal As DAO.Database

Dim tbl As DAO.TableDef
Dim fld As DAO.Field

Dim tblFinal As DAO.TableDef
Dim fldFinal As DAO.Field
Dim prpFinal As DAO.Property
Set dbFinal = DBEngine.OpenDatabase("D:\Dropbox\Expedientes JLE nueva epoca activos\17002 - Fermin Torres. Programa\NuevoFoasat.accdb")

For Each tbl In CurrentDb.TableDefs

    If InStr(tbl.Name, "JLE_") > 0 Then

        For Each fld In tbl.Fields

            Set tblFinal = dbFinal.TableDefs(tbl.Name)
            Set fldFinal = tblFinal.Fields(fld.Name)

            On Error GoTo ErrorTrap

            If Nz(fld.Properties("Description"), "") <> "" Then

                Set prpFinal = fldFinal.CreateProperty("Description")
                prpFinal.Type = dbText
                prpFinal.Value = fld.Properties("Description")


                    fldFinal.Properties.Append prpFinal

                'Debug.Print fldFinal.Name, fldFinal.Properties("Description")

                fldFinal.Properties("Description") = fld.Properties("Description")

            End If

            On Error GoTo 0

        Next fld

    End If

Next tbl

dbFinal.Close
Set dbFinal = Nothing
Exit Sub

ErrorTrap:

    If Err.Number = 3367 Then

        Debug.Print "Property already exists on " & tbl.Name & " (Field: " & fld.Name & ")"

    Else
    Stop
        Debug.Print "Not Found or empty on " & tbl.Name & " (Field: " & fld.Name & ")"

    End If

    Resume Next

End Sub
Javier
  • 189
  • 3
  • 16