Results 1 to 3 of 3
  1. #1
    bbrazeau is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    101

    Update Query?? or RecordSet??

    I have tblParts, tblRfqs, tblRfqDetails,tblQuotes. tblParts has a field txtStatus among others. The value of this field can be "Quoting", "Quoted" or "P.O. Issued"(taken from a value list not a lookup from another table). Table tblRfqDetails is a join table with PartID and RfqID as fields among others. I would like to have a command button on the Quoting form (1 to1 relationship with Rfqs) that would change the status of the Parts that are in the RfqDetails subform to "P.O. Issued". Then open a tblPO to a new record and fill in a field Quote with the current QuoteID.
    I have an update query that I think will work.(criteria to find correct Rfq in fqDetails is [Forms]![frmQuotes]![Rfq] now how do I get the command button to run this code? I tried docmd.runquery theres no such command. Can I use the runSQL command? If so what would the code line look like. I've used an SQL statement before to limit choices in a combo box and I had to add double Quote marks around 1 of the where conditions.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    You can open a saved Access query with DoCmd.OpenQuery. The OpenQuery method opens a select or crosstab query in Datasheet view, Design view, or Print Preview - or runs an action query from code.

    Or you can build the SQL in code and run it.
    DoCmd.RunSQL "UPDATE ..."

    Both of those will provoke warning messages. To avoid them use DoCmd.SetWarnings False and DoCmd.SetWarnings True.

    Another method to run SQL actions is (no warning popups):
    CurrentDb.Execute "UPDATE ..."

    Review this article http://www.databasejournal.com/featu...n-VBA-Code.htm
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    bbrazeau is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    101

    RunSQL method

    Thank you June7, Following is the code I used to make this work. I will impliment the DoCmd.SetWarnings you mentioned and the error checking mention in the article you referenced. I'm going to experiment with the SQL I wrote also. I think it may be more complex than it needs to be. I'm going to mark this thread as solved. Again Thank you.

    Private Sub cmdNewPo_Click()
    Dim strSQL As String
    strSQL = "UPDATE tblParts INNER JOIN (tblRfqs INNER JOIN tblRfqDetails ON tblRfqs.RfqID = tblRfqDetails.Rfq) ON tblParts.PartID = tblRfqDetails.Part SET tblParts.PartStatus = ""P.O. Received"" WHERE (((tblRfqDetails.Rfq)=[Forms]![frmQuotes]![Rfq]) AND ((tblRfqDetails.Part)=[tblParts]![PartID]));"
    If DCount("Quote", "tblPOs", "Quote =" & Me.QuoteID) = 0 Then
    DoCmd.RunSQL strSQL
    DoCmd.OpenForm "frmPOsAdd", , , , acFormAdd
    Else
    MsgBox ("This Quote already has a Purchase Order")
    End If
    End Sub

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

Similar Threads

  1. Update combo box from recordset
    By kc1 in forum Access
    Replies: 5
    Last Post: 12-12-2011, 06:14 PM
  2. Replies: 6
    Last Post: 12-01-2011, 10:54 AM
  3. Replies: 3
    Last Post: 08-03-2010, 02:24 PM
  4. Replies: 1
    Last Post: 07-17-2010, 08:55 PM
  5. Replies: 2
    Last Post: 10-01-2009, 03:39 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