Results 1 to 2 of 2

Thread: Access, VB and dao question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    89
    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?

    Thank you

  2. #2
    Swatty
    Guest

    Thumbs up

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width