Results 1 to 3 of 3

How to update an autonumber using vba

Threaded View

  1. #1
    Registered User
    Join Date
    07-28-2005
    Posts
    73

    How to update an autonumber using vba

    I have two tables in sql

    One is a supplier table with an autonumber supID,supname
    Another is a product table with productID,supname,supaddress,start year and end year.

    Now I get data for supname,supaddress,startyear and endyear using inputbox in vba.

    I have to use ADO connection to insert it into sql tables.

    I don;t know how to populate the autonumber field.
    Below is the code..
    let me know if it will work...

    Thanks


    SupName = InputBox("Enter the SupplierName", "Name?", "")
    SupAddress = InputBox("Enter the Address", "Address?", "")
    Startyr = InputBox("Enter the Start Year", "StartYear?", "")
    EndYr = InputBox("Enter the End Year","EndYear?","")


    Set cnn = CreateObject("ADODB.Connection")
    connstring = "ODBC;DRIVER=SQL Server;SERVER=servname;DATABASE=dbname;Trusted_Connection=YES"
    cnn.Open
    Set rs = CreateObject("ADODB.Recordset")


    sSQL = "INSERT INTO supplier (SupID,SupName"
    sSQL = sSQL & ") VALUES ("," "& SupName &


    sSQL = "INSERT INTO product ("productID,SupName,supplieraddress,StartYear,EndYear"
    sSQL = sSQL & ") VALUES (" ," "& SupName & "," & SupAddress & "," & Startyr & "," & EndYr & ","


    rs.Close
    cnn.Execute sSQL

    Set rs=Nothing
    cnn.close
    Last edited by hvisa; 07-15-2009 at 04:08 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1