inserting autonumbers in SQL.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Karen Hill

    #1

    inserting autonumbers in SQL.

    I have a two value table where the first field is an autonumber. I
    wrote an SQL statement in visual basic for applications to insert but
    it fails.

    This is the code:

    DoCmd.RunSQL "INSERT INTO Table1 VALUES(,cat);", True

    The first one I didn't include a value because it is an autonumber and
    I expected JET to automatically put in the next value. How can I get
    it to work?

    thanks.

  • Salad

    #2
    Re: inserting autonumbers in SQL.

    Karen Hill wrote:[color=blue]
    > I have a two value table where the first field is an autonumber. I
    > wrote an SQL statement in visual basic for applications to insert but
    > it fails.
    >
    > This is the code:
    >
    > DoCmd.RunSQL "INSERT INTO Table1 VALUES(,cat);", True
    >
    > The first one I didn't include a value because it is an autonumber and
    > I expected JET to automatically put in the next value. How can I get
    > it to work?
    >
    > thanks.
    >[/color]
    Dim strSQL As String
    strSQL = "Insert Into Table1 (FieldName) Values ('cat');"
    DoCmd.RunSQL strSQL

    You don't need to concern yourself with adding an autonumber. That is
    done automatically when you insert the record.

    Comment

    Working...