Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2015
    Posts
    12

    DoCmd.RunSQL help!

    Hi everyone and just wanted to say a big thank you for helping me out... I have the query written successfully, but am struggling to get the information entered successfully in the events/After Update.

    Below is my code:
    table append from = Item Master
    table append to = RM_Pricing
    field = RM_Code

    When I enter new information to the RM_Code field it gives me "you are about to append 0 rows" but when I click on the query it actually populates the info.

    ------------------------------------------------------


    Private Sub RM_CODE_AfterUpdate()




    DoCmd.RunSQL "INSERT INTO tblRM_Pricing ( RM_CODE )" & _
    "SELECT [tblItem Master].RM_CODE AS Expr1 " & _
    "FROM [tblItem Master] LEFT JOIN tblRM_Pricing ON [tblItem Master].RM_CODE = tblRM_Pricing.RM_CODE " & _
    "WHERE (((tblRM_Pricing.RM_CODE) Is Null));"


    End Sub

    ----------------------------------------------------

    Big thanks again!

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    It is likely you will get multiple msgs regarding the updates because you have nested subqueries. If you want to validate the number of records that will be affected you can use some other methods to update. Alternatively, you can suppress the messages. Yet, another option would be to use
    Code:
    'As a simple example how to employ
    CurrentDB.Execute "Insert your statement", dbFailOnError

  3. #3
    Join Date
    Nov 2015
    Posts
    12
    doesn't work

    It's still not updating my other table [tblRM_Pricing] when i changed the DoCmd.RunSQL to CurrentDB.Execute

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I am not fully understanding. Sometimes it works and other times it does not? I based my previous response mostly on your following statement. Perhaps you can elaborate and what you are doing when it works and what you are doing when it does not work.
    When I enter new information to the RM_Code field it gives me "you are about to append 0 rows" but when I click on the query it actually populates the info.

  5. #5
    Join Date
    Nov 2015
    Posts
    12
    Hi:

    The query works when I manually run it. What I'm trying to do is automate the query in the event properties and have it run automatically when a user enters new data (RM_CODE) field in the "Item_Master" table. When new data is enter it should trigger the query in the event property to create the same record in the RM_Pricing table. Currently, it is not doing it at automatically, but if I manually run the query it works. Thanks

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    What is the name of the query that functions correctly? You can use the name of the query in your VBA code.
    currentdb.execute "MyQueryName"

    Maybe your VBA code is not executing.
    Msgbox "Attempting Now"
    currentdb.execute "MyQueryName"

    When I stare at your SQL statement. Nothing is jumping out as incorrect. The only thing I can see that I would of typed would be ( RM_CODE ) " & _ instead of ( RM_CODE )" & _

    But I do not think that matters and if it did matter, you would get an error.

    Go ahead and try running the query object using the name of the query and the message box. Also, post the actual SQL from the object here.

  7. #7
    Join Date
    Nov 2015
    Posts
    12
    I got it resolved. I used DoCmd.OpenQuery "Query1" did the trick... It was the placement of where I created the event it should be after I closed the application not when I entered the first bit of record.

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Glad to hear you were able to get it working and thanks for posting how you resolved your issue.

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

Similar Threads

  1. Queries vs VBA DoCmd.RunSQL
    By ck4794 in forum Programming
    Replies: 1
    Last Post: 10-27-2013, 10:31 AM
  2. DoCmd.RunSQL
    By Access_Blaster in forum Programming
    Replies: 6
    Last Post: 07-23-2013, 09:27 PM
  3. my first DoCmd.RunSQL
    By broecher in forum Programming
    Replies: 4
    Last Post: 11-05-2010, 09:35 PM
  4. docmd.runsql update
    By Mitch_Aus in forum Programming
    Replies: 2
    Last Post: 10-05-2010, 09:45 AM
  5. docmd.runsql not working
    By Rameez in forum Programming
    Replies: 3
    Last Post: 08-07-2009, 10:07 AM

Tags for this Thread

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