Results 1 to 2 of 2
  1. #1
    chaitanyakvs is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Posts
    1

    Access wont insert the record

    Good Morning All,


    I have two tables Called Roadway table and Count table.
    The composite primary key in the count table being (County+station+stationDirection+Date)

    There is a one to many relationship from roadway table to count table on the following fields(county,station,stationdirection,keyno)
    I am trying to add a record on the count table through an insert statement with a different Date Through access 2007 vba. Access runs the sql without any error Message, but wont insert the record in the table.

    IF there is a record in the count table like(countyx,stationx,stationdirectionL,02/05/2010,keyno)..
    I am trying to add a record like((countyx,stationx,stationdirectionL,Todays Date,keyno)

    My VBA code to inser the record is is as follows :-

    Code:
    Private Sub btnOk_Click()
            Dim x As String
            Dim strsql2 As String
            Dim strsql As String
            Dim db As Database
    
         Set db = CurrentDb()
    
      strsql = "INSERT INTO [Count table] ( Co, [Station#], [Station Direction], CTDate, keyno )"
      strsql2 = strsql & " VALUES('" & Me.County & "','" & Me.Station & "','" & Me.[Station Direction] & "',#" & Me.NewDate & "#,'" & Me.keyno & "');"
      MsgBox (strsql2)
    
      db.Execute strsql2
    
    MsgBox ("Record inserted")
    
    End Sub



    Any help is greatly appreciated. I am unable to attach the screen shots. Will figure it out and post.

    Regards,
    Chaitanya


  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Change this line and see if you get a descriptive error:

    db.Execute strsql2, dbFailOnError
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 12-16-2010, 12:45 PM
  2. Replies: 7
    Last Post: 12-15-2010, 09:46 AM
  3. Help about access INSERT INTO statement
    By ducthang88 in forum Programming
    Replies: 7
    Last Post: 12-03-2010, 08:40 AM
  4. Insert Record checks table
    By pfarnell in forum Forms
    Replies: 13
    Last Post: 09-05-2010, 10:47 AM
  5. Access insert into query...
    By xmetisx in forum Queries
    Replies: 2
    Last Post: 04-06-2010, 02:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums