+ Reply to Thread
Results 1 to 2 of 2

Problem when adding a new record using VB

  1. #1
    Registered User
    Join Date
    02-26-2009
    Location
    U.S
    MS-Off Ver
    Excel 2003
    Posts
    42

    Problem when adding a new record using VB

    Hi,

    I have a database with one Table and one Form.

    The table "Table1" fields:
    ID (AutoNumber),
    Date (Date/Time),
    Mark (Number)

    In Form "Form1" is a button. When I press the button I want to add a new record in table "Table1" with these values:

    "17-jan-2009"

    and "15" for Date and Mark.

    Currently I have this code for onClick event:

    Please Login or Register  to view this content.
    But I get an error: "Syntax error in INSERT INTO statement". Why ? Because of field ID which is AutoNumber type ?

  2. #2
    Registered User
    Join Date
    03-20-2008
    Location
    Buffalo, NY USA
    Posts
    43

    Re: Problem when adding a new record using VB

    This should work:

    Please Login or Register  to view this content.
    There are a few things wrong with the original phrasing. In Access, Dates are surrounded by a #. Also the [Mark] field is a number, which doesn't require a pair of single quotes around it. The single quotes would infer a text value. The Insert stament also requires a following Select statement (query) to insert the values. Finally, it's not a direct issue in your failure, but be careful with using [Date] as a field name. "Date" is a reserved word (designating a data type) and can get you into trouble when using it as a field name (the voice of hard experience). Hope this helps...

    Brent

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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