-
Hi,
I'm writing an application in VB where I have to create a new Access table at a run time. Every time my program adds a new record I need to generate a new primary key value. I tryed to use AutoNumber field type but vb doesn't seems to have it (or it could not find it. When I tryed to return the type of the AutoNumber field it returned 4 which is a Number type).
Is there anything else that could be done apart from DBGUID type? :confused:
Thank you
-
Dim m_conn As ADODB.Connection
Set m_conn = New ADODB.Connection
m_conn.ConnectionString = "Your connection"
Dim strSQL As String
strSQL = "Create Table YOUR_TABLE (FIRST_COL int Not Null, "
strSQL = strSQL & "SECOND_COL int Not Null, OTHER_COL int Not Null, "
strSQL = strSQL & "Last_COL datetime Null)"
m_conn.Open
m_conn.BeginTrans
m_conn.Execute strSQL
strSQL = "ALter Table YOUR_TABLE Add Constraint PK_FIRTS_COL Primary Key" & _
" Nonclustered ( FIRST_COL )"
m_conn.Execute strSQL
m_conn.CommitTrans
m_conn.Close
Set m_conn = Nothing