"Lotto" <lo********@hotmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Hello,
i've looked in a lot of places but can't seem to find the answer, so I
hope you can help me.
I've made programmatically a table in an access database with keys.
The foreign keys I can find (in the MSysObjects) but where can I find
the primary keys???
I want to check whether the keys I have made are correct (when
something goes wrong)
You should not be using MSysObjects at all - you have no guarantee about the
structure and it is not put there for programmers to write code for. You
should be using something like the DAO object library together with error
handling to make sure that the table you create is correct. In this example
function, I get a value of True returned if the table was correctly created
including the setting up of the primary key:
Public Function CreateTempTable() As Boolean
On Error GoTo Err_Handler
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim idx As DAO.Index
Set dbs = CurrentDb
Set tdf = dbs.CreateTableDef("tblTemp")
Set fld = tdf.CreateField("TmpID", dbLong)
tdf.Fields.Append fld
Set idx = tdf.CreateIndex("TmpID")
idx.Primary = True
Set fld = idx.CreateField("TmpID")
idx.Fields.Append fld
tdf.Indexes.Append idx
Set fld = tdf.CreateField("TmpText", dbText, 50)
tdf.Fields.Append fld
dbs.TableDefs.Append tdf
dbs.TableDefs.Refresh
CreateTempTable = True
Exit_Handler:
If Not idx Is Nothing Then
Set idx = Nothing
End If
If Not fld Is Nothing Then
Set fld = Nothing
End If
If Not tdf Is Nothing Then
Set tdf = Nothing
End If
If Not dbs Is Nothing Then
Set dbs = Nothing
End If
Application.RefreshDatabaseWindow
Exit Function
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler
End Function