Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2009
    Posts
    14

    Unanswered: Insert SQL command with autonumber fields

    Greetings to everyone,

    I have a table tblCountryState with the following structure
    pkID : Autonumber
    Country : Text
    State : Text

    Besides this I also have other tables
    tblStateCiry,
    pkID : Autonumber
    State : Text
    City : Text

    tblCountry.
    pkID : Autonumber
    Country : Text

    I have created a data capture form, where the user fills in the details. When he selects the Country from a ComboBox, the State list, another combobox is filled in with the criteria where the field Country in the tblCountryState matches that of the Country ComboBox.Value.

    Now I also present an option "[OTHERS]" in the State ComboBox, added using a UNION Query. So, when the "[OTHERS]" option is selected I ask the user to give the name of New Data using a InputBox. Once I get the value, I try to INSERT the value in the tblCountryState table. Since I have a AutoNumber Filed, my SQL doesn't work.

    My SQL Statement is:

    "Insert into tblCountryState values ('" & Country.Value & "','" & strValue & "')"

    Here strValue is the input gathered from InputBox.

    Can some one please point me where the error is?

    Thanks and regards,
    Sakthivel

    I am using Access 2003 on Windows XP SP 3

  2. #2
    Join Date
    May 2009
    Posts
    258
    Try the following SQL statement:
    Code:
    "INSERT INTO tblCountryState (Country, State) VALUES ('" & Country.Value & "','" & strValue & "')"
    Ax

  3. #3
    Join Date
    Jun 2009
    Posts
    14

    Re: Insert Command

    Thanks,

    It's working great.

    Thanks for the solution.

  4. #4
    Join Date
    May 2009
    Posts
    258
    Great to hear!

Posting Permissions

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