Results 1 to 2 of 2
  1. #1
    Phred is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    Dec 2009
    Posts
    246

    Two SQL Queries (append and update) in VBA Record Lock

    First a thanks to all who have been patiently helping me.

    I am using Access 2007

    I have a modest level of experience with VBA and SQL.

    I have a Command button on a form - it runs an Append Query which functions fine, and it appends the new record correctly to the Tbl_SiteCategory

    There may be some errors in the queries as I have been trying everything.

    QUERY 1 Insert Into


    __________________________________________________ ___________

    Dim intSiteID As Integer, stSiteName As String, stCustID As String, stCustNm As String, stSQL As String

    intSiteID = Forms!Frm_Modal_AttachCategory!SiteID

    stSiteName = Forms!Frm_Modal_AttachCategory!SiteName

    stCustID = Forms!Frm_Modal_AttachCategory!CustomerID

    stCustNm = Forms!Frm_Modal_AttachCategory!CustomerName

    stSQL = "INSERT INTO Tbl_SiteCategory" _
    & "( CustomerID, CustomerName, SiteID, SiteName )" _
    & " VALUES (""" & stCustID & """,""" & stCustNm & """,""" & intSiteID & """,""" & stSiteName & """);"

    DoCmd.SetWarnings False

    DoCmd.RunSQL stSQL

    DoCmd.Save

    Requery

    Refresh

    DoCmd.SetWarnings True

    MsgBox "The new record has been added. Now select the Category, enter the Default Meal Count, and then click the Update Category button.", vbOKOnly


    QUERY 2 Updates the Above record.
    __________________________________________________ _________
    The user makes further changes to the new record created above and then click on a command button to run the following update query.

    Dim inCatID As Integer, stCatName As String, stCatID As String, inMealCt As Integer, stSQL As String

    inCatID = Forms!Frm_Modal_AttachCategory!Frm_Modal_AttachCat egory2!SiteCategoryID

    stCatName = Forms!Frm_Modal_AttachCategory!Frm_Modal_AttachCat egory2!PickCat.Column(0)

    stCatID = Forms!Frm_Modal_AttachCategory!Frm_Modal_AttachCat egory2!PickCat.Column(1)

    inMealCt = Forms!Frm_Modal_AttachCategory!Frm_Modal_AttachCat egory2!DFMealCount

    DoCmd.SetWarnings False

    stSQL = "UPDATE Tbl_SiteCategory" _
    & " SET Category = '" & stCatName & "'," _
    & " CategoryID = '" & stCatID & "'," _
    & " DefaultMealCount = " & inMealCt & "" _
    & " WHERE SiteCategoryID = " & inCatID & ";"

    DoCmd.RunSQL stSQL

    DoCmd.Save

    Requery

    Refresh

    DoCmd.SetWarnings True

    This code will not finish. I encounter several problems

    I get a warning that the record is locked by another user. I am the only on on the machine.

    Then the warning that the record cannot be saved right now.

    If I click save anyhow, I get all kinds of corruption in the table and its trashed.

    I think somehow I am not "closing out" the first query. I am not sure how to. I have put Save, Requery, Refresh to no avail.

  2. #2
    Phred is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    Dec 2009
    Posts
    246

    Additional info

    Additional Info. First Query seems to work fine. When I run the second update query I get the Write Conflict dialog box. If I click the Save Record button it destroyes the table. If I click the Drop Changes button the second query updates the table perfectly.

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

Similar Threads

  1. Append Queries
    By HunterEngineeringCoop in forum Queries
    Replies: 8
    Last Post: 12-12-2012, 01:10 PM
  2. Replies: 3
    Last Post: 03-11-2012, 03:35 PM
  3. Lock Record for Editing on a Linked table
    By khalid in forum Programming
    Replies: 3
    Last Post: 06-14-2011, 08:37 AM
  4. lock a record
    By Nokia N93 in forum Programming
    Replies: 3
    Last Post: 02-21-2011, 02:51 PM
  5. Replies: 5
    Last Post: 06-29-2010, 06:10 AM

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