P
Peter Hibbs
I am using Access 2007 (in the new .accdb mode) and I am trying to add
the new Attachment field type to a table in the back-end file using
VBA code in the front-end.
Unfortunately there is very little information on the Internet about
this subject so I am having to guess on how the code should work. I am
using the code from Allen Browne's site as a starter. The problem is
that I'm not entirely sure of the syntax for the CreateField function,
I'm guessing that the second parameter is 'dbAttachment' and the last
parameter is irrelevant (I have set it to 1).
This is the code in the FE that I am using :-
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim vPathname As String
vPathname = "C:\Access Test\Database_be.accdb"
Set db = OpenDatabase(vPathname) Set tdf =
db.TableDefs("tbl_BE_Table")
tdf.Fields.Append tdf.CreateField("NameOfField", dbAttachment, 1)
Set tdf = Nothing
Set db = Nothing
RefreshDatabaseWindow
The weird thing is that the code appears to work, no errors, and the
new field is appended to the table correctly but when I try to open
the table from the front end I get this error message :-
'The search key was not found in any record.'
The same thing happens if I try to open the table in Design mode (from
the FE), after the usual 'you cannot modify this table,etc' message I
get the same error message. However, if I then open the BE file and
open the table, the new field is there and I can do all the usual
things with it with no problems. If I use the same code for other
types of fields, dbText, dbMemo, etc, it works correctly so it appears
to be a problem with the dbAttachment type fields..
If I execute the same code to add an Attachment field to a table in
the FE it works fine. The field is appended to the table and I can
open the table as normal. This code looks like this :-
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Set db = CurrentDb()
Set tdf = db.TableDefs("tbl_FE_Table")
tdf.Fields.Append tdf.CreateField("NameOfField", dbAttachment, 1)
Set tdf = Nothing
Set db = Nothing
RefreshDatabaseWindow
Is this a bug in A2007 or am I missing something. Can anyone reproduce
the problem, does anyone know how to fix it.
Peter Hibbs.
the new Attachment field type to a table in the back-end file using
VBA code in the front-end.
Unfortunately there is very little information on the Internet about
this subject so I am having to guess on how the code should work. I am
using the code from Allen Browne's site as a starter. The problem is
that I'm not entirely sure of the syntax for the CreateField function,
I'm guessing that the second parameter is 'dbAttachment' and the last
parameter is irrelevant (I have set it to 1).
This is the code in the FE that I am using :-
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim vPathname As String
vPathname = "C:\Access Test\Database_be.accdb"
Set db = OpenDatabase(vPathname) Set tdf =
db.TableDefs("tbl_BE_Table")
tdf.Fields.Append tdf.CreateField("NameOfField", dbAttachment, 1)
Set tdf = Nothing
Set db = Nothing
RefreshDatabaseWindow
The weird thing is that the code appears to work, no errors, and the
new field is appended to the table correctly but when I try to open
the table from the front end I get this error message :-
'The search key was not found in any record.'
The same thing happens if I try to open the table in Design mode (from
the FE), after the usual 'you cannot modify this table,etc' message I
get the same error message. However, if I then open the BE file and
open the table, the new field is there and I can do all the usual
things with it with no problems. If I use the same code for other
types of fields, dbText, dbMemo, etc, it works correctly so it appears
to be a problem with the dbAttachment type fields..
If I execute the same code to add an Attachment field to a table in
the FE it works fine. The field is appended to the table and I can
open the table as normal. This code looks like this :-
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Set db = CurrentDb()
Set tdf = db.TableDefs("tbl_FE_Table")
tdf.Fields.Append tdf.CreateField("NameOfField", dbAttachment, 1)
Set tdf = Nothing
Set db = Nothing
RefreshDatabaseWindow
Is this a bug in A2007 or am I missing something. Can anyone reproduce
the problem, does anyone know how to fix it.
Peter Hibbs.