+ Reply to Thread
Results 1 to 3 of 3

How to update an autonumber using vba

  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.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How to update an autonumber using vba

    Hello hvisa,

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

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

    Re: 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


    Please Login or Register  to view this content.

+ Reply to Thread

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