Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    ds_8805 is offline Novice
    Windows XP Access 2002
    Join Date
    Jan 2010
    Posts
    27

    record saving twice in table

    Hi Everyone! i have a form where the user will have to enter details relating to a site and click on save record in order for the details to be saved into the table. However I am facing a problem.

    When I click save record after entering the details, the record gets saved onto the table twice. Then when I go on to enter a new site and its details, one of the entry of the previous one i added( which has double entry) gets deleted and the current new one gets 2 entries in the table.
    Could someone pls tell me what I might be doing wrong.



    thanks

  2. #2
    Datagopherdan is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Dec 2008
    Posts
    220
    My first question is, why do you have a Save button? Do you have it setup where if the user does not click that button, the entered data will be undone or a delete query will be ran to remove the user's entries? Access is unlike Word and Excel where you would need to save the changes. It does this automatically.

    Dan
    Access Development

    Quote Originally Posted by ds_8805 View Post
    Hi Everyone! i have a form where the user will have to enter details relating to a site and click on save record in order for the details to be saved into the table. However I am facing a problem.

    When I click save record after entering the details, the record gets saved onto the table twice. Then when I go on to enter a new site and its details, one of the entry of the previous one i added( which has double entry) gets deleted and the current new one gets 2 entries in the table.
    Could someone pls tell me what I might be doing wrong.

    thanks

  3. #3
    ds_8805 is offline Novice
    Windows XP Access 2002
    Join Date
    Jan 2010
    Posts
    27
    hey thanks for ur reply... the main purpose of my save button right is to give the assurance to the user that the record is saved and it would give a msg saying that the site is saved.. I have done similar thing in other forms but I have not encountered such a problem before!

    thanks

  4. #4
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    well, whatever the purpose behind the save button is, that's what's causing your issue. it is being saved when the textboxes are filled, then again when the save button is being saved. If you want to only have it save when the button is pressed. have unbound textboxes and use an INSERT INTO sql statement to populate your table when the Save button is pressed.

  5. #5
    ds_8805 is offline Novice
    Windows XP Access 2002
    Join Date
    Jan 2010
    Posts
    27
    hey thanks for ur reply.. I m not fully getting wat u mean.. can u explain more on how to go about doing this? thank u

  6. #6
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    ok lets assume you have 2 fields (this can be expanded obviously) that you need to create, ID and Name. you will create 2 txtboxes, txtID and txtName, and a button, cmdSave.

    you will then choose "even procedure" from the button's on click event in the properties box. This will open up a VBA editor and an empty sub for you to fill in. your code will be:

    Code:
    dim strSQL as String
    
    strSQL = "INSERT INTO myTable (columnID, columnName) VALUES (" &  Forms!myFrm!txtID & "," & Forms!myFrm!txtName & ");"
    
    docmd.RunSQL (strSQL)
    adjust myTable, myFrm, etc to make it work with what you have.

  7. #7
    ds_8805 is offline Novice
    Windows XP Access 2002
    Join Date
    Jan 2010
    Posts
    27
    Thank u! I will try this way u suggested!

  8. #8
    ds_8805 is offline Novice
    Windows XP Access 2002
    Join Date
    Jan 2010
    Posts
    27
    Hello again! I tried implementing the way u said. However I keep getting error. I have pasted the error msg here:
    The expression On Click you entered as the event property setting produced the following error:
    Argument not optional

    This is my code
    Private Sub Command4_Click()
    Dim strSQL As String
    strSQL = "INSERT INTO Capex Site Info (SiteID, SiteName) VALUES (" & Forms![testing33322222221]![SiteID] & "," & Forms![testing33322222221]![SiteName] & ");"
    DoCmd.RunSQL
    End Sub


    am i doing smthg wrong?

  9. #9
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    docmd.runSQL (strSQL)

    also change the name of your table to one word. dont have a multiple word table name. just bad practice. wrap the table name in brackets for now.

  10. #10
    ds_8805 is offline Novice
    Windows XP Access 2002
    Join Date
    Jan 2010
    Posts
    27
    sorry I had just realised that mistake and edited it.. now the error it gives is that there is some problem with the insert into syntax! However when I went to check the syntax online, it seems to be correct only! any idea? sorry for the trouble!

  11. #11
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    try commenting out the docmd.runsql by putting a ' infront of it. then after the strSQL = line, enter debug.print strSQL and then in the window at the bottom it will display what is stored in strSQL. make sure it looks correct there. outside of that, i dont know what to tell you.

  12. #12
    ds_8805 is offline Novice
    Windows XP Access 2002
    Join Date
    Jan 2010
    Posts
    27
    hey u noe i tried but nothing in displayed! there is no window

  13. #13
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    oh, look for the option for the "immediate window" i dont have access here at home and dont remember off the top of my head how to get it.

  14. #14
    ds_8805 is offline Novice
    Windows XP Access 2002
    Join Date
    Jan 2010
    Posts
    27
    hey for only the date we have to use blah blah date"#" instead of "," right?

  15. #15
    Datagopherdan is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Dec 2008
    Posts
    220
    Shabz's is right and that will work but an alternative to Docmd.RunSQL and generally the better way to go is to use CurrentDB.Execute. This does not rely on the Docmd.Setwarnings command as RunSQL does.

    Also, you have to careful doing this and generally theres not really a need for it. You can give them a confirmation message sayng that the record was committed but you should not be running a query like that to add it. You're opening yourself for alot of possible problems, such as users accidentally clicking that button when the record has already been added and then you have duplicates.

    Really, the only reason that I can think of to do something like this is if you wanted some type of quality control where the record would be validated by management before being committed but even with that, you would not need to run an append query. You could just have a check box that management would check after they validated the record and some code, so it would be displayed when that value =-1.

    Dan
    Access Development

    Quote Originally Posted by ds_8805 View Post
    hey for only the date we have to use blah blah date"#" instead of "," right?

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Auto-fill field not saving to table
    By aaid in forum Forms
    Replies: 1
    Last Post: 12-18-2009, 05:34 PM
  2. table name as record
    By stigmatized in forum Access
    Replies: 1
    Last Post: 11-23-2009, 04:34 AM
  3. Auto Populated Field not Saving to Table
    By EstesExpress in forum Forms
    Replies: 4
    Last Post: 10-09-2009, 03:33 AM
  4. Move a record from one table to another table.
    By botts121 in forum Programming
    Replies: 4
    Last Post: 06-25-2009, 12:53 PM
  5. saving a list box to access table
    By newguy357 in forum Forms
    Replies: 0
    Last Post: 05-05-2006, 12:22 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