CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Auto Number

  1. #1
    Join Date
    Dec 2000
    Location
    Colombo,Srilanka
    Posts
    50

    Auto Number

    Hi There,
    1. Is there any way to check the next number of the AutoNumber format of a Access table.
    I want to know this for a table whish have zero records.
    2. How to initialise the Access table Auto number to 1 by PROGRMATICALLY.



    Dinesh Asanka

  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Auto Number

    1. Is there any way to check the next number of the AutoNumber format of a Access table.
    I want to know this for a table whish have zero records.

    YOu can execute SQL
    SQL = "select max(AutoNumberField) as X from YourTable"
    rs.Open SQL,Conn,adOpenDynamic,adLockOptimistic
    The next number will be rs!X

    2. How to initialise the Access table Auto number to 1 by PROGRMATICALLY.
    'set reference to ADOX

    Set col = New ADOX.Column
    Set col.ParentCatalog = cat
    With col
    .Type = adInteger
    .Name = "ID"
    .Properties("Autoincrement") = True
    End With
    tbl.Columns.Append col


    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    Apr 2001
    Posts
    3

    Re: Auto Number

    hello dinesh,
    here is the code for auto numbering e.g.
    access table = table1
    field datatype
    no number
    name text
    vb recordset=rs
    dim m_no as integer
    now the syntex as below
    rs.open "select *from table1"
    if rs.bof=true and rs.eof=true then
    m_no=1
    else
    rs.movelast
    m_no=(rs.feilds(0).value) + 1
    end if
    rs.close
    text1.text=m_no
    otherwise
    u cam also write code like
    if rs.recordcount <> 0 then
    rs.movelast
    m_no=rs.feilds(0).value+1
    else
    m_no=1
    end if
    but this other option is only properly work with
    adocursure=openkeyset,lock=adooplimestic
    if till u've an error mail me. all the best.
    Jalpa Shah









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

Featured