Results 1 to 8 of 8
  1. #1
    jazzy is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Nov 2021
    Posts
    77

    Query Failing but if i run manually it works

    Run-time error '3067' Query or Input must contain at least one table or query. i created 2 manual queries Contract Guests and Contract Guests for Ceremony to help diagnose the issue. it appears that there is no value when it gets to DoCmd.RunSQL sqlOrigCeremonyCount if i end the code and manually run the Query values are there and they work fine. if i manually run the queries while in debug the queries have no values. any help woudl be appreciated



    Code:
    Private Sub PostDeposits_Click()Dim sqlDeposit1 As String
    Dim sqlDeposit2 As String
    Dim sqlDeposit3 As String
    Dim sqlBalance As String
    Dim sqlOrigGuestCount As String
    Dim sqlOrigCeremonyCount As String
    
    
    If DCount("ContractsID", "tbl_Invoice", "[ContractsID] = [Forms]![frm_Contract]![ContractsID]") = 0 Then
    
    
    sqlDeposit1 = "INSERT INTO tbl_Invoice ( ContractsID, InvoiceDate, AmountDue, Description)" & _
    "SELECT tbl_Contracts.ContractsID, [Forms]![frm_Contract]![1stDepositDue] AS 1stDepositDue, [Forms]![frm_Contract]![1stDepositAmount] AS 1stDepositAmount, '1st Deposit'" & _
    " FROM tbl_Contracts WHERE(tbl_Contracts.ContractsID) = [Forms]![frm_Contract]![ContractsID]"
    
    
    sqlDeposit2 = "INSERT INTO tbl_Invoice ( ContractsID, InvoiceDate, AmountDue, Description)" & _
    "SELECT tbl_Contracts.ContractsID, [Forms]![frm_Contract]![2ndDepositDue] AS 2ndDepositDue, [Forms]![frm_Contract]![2ndDepositAmount] AS 2ndDepositAmount, '2nd Deposit'" & _
    " FROM tbl_Contracts WHERE(tbl_Contracts.ContractsID) = [Forms]![frm_Contract]![ContractsID]"
    
    
    sqlDeposit3 = "INSERT INTO tbl_Invoice ( ContractsID, InvoiceDate, AmountDue, Description)" & _
    "SELECT tbl_Contracts.ContractsID, [Forms]![frm_Contract]![3rdDepositDue] AS 3rdDepositDue, [Forms]![frm_Contract]![3rdDepositAmount] AS 3rdDepositAmount, '3rd Deposit'" & _
    " FROM tbl_Contracts WHERE(tbl_Contracts.ContractsID) = [Forms]![frm_Contract]![ContractsID]"
    
    
    sqlBalance = "INSERT INTO tbl_Invoice ( ContractsID, InvoiceDate, AmountDue, Description)" & _
    "SELECT tbl_Contracts.ContractsID, [Forms]![frm_Contract]![BalanceDue] AS BalanceDue, [Forms]![frm_Contract]![BalanceAmount] AS BalanceAmoun, 'Final Balance'" & _
    " FROM tbl_Contracts WHERE(tbl_Contracts.ContractsID) = [Forms]![frm_Contract]![ContractsID]"
    
    
    sqlOrigGuestCount = "INSERT INTO tbl_InvoiceLineItem ( ContractsID, InvoiceIDDate, InvoiceID, InvoiceLineItemDesc, InvoiceLineItemQty, InvoiceLineItemCost, Tax, ServiceCharge )" & _
    "SELECT tbl_Invoice.ContractsID, Date() AS InvoiceIDDate, Last(tbl_Invoice.InvoiceID) AS LastOfInvoiceID, ""Contract Guests"" AS InvoiceLineItemDesc, tbl_Contracts.MinGuaranteed, 0 AS InvoiceLineItemCost, -1 AS Tax, -1 AS ServiceCharge " & _
    "FROM tbl_Invoice INNER JOIN tbl_Contracts ON tbl_Invoice.ContractsID = tbl_Contracts.ContractsID " & _
    "GROUP BY tbl_Invoice.ContractsID, Date(), ""Contract Guests"", tbl_Contracts.MinGuaranteed, 0, -1 " & _
    "HAVING (((tbl_Invoice.ContractsID)=[Forms]![frm_Contract]![ContractsID]));"
    
    
    sqlOrigCeremonyCount = "INSERT INTO tbl_InvoiceLineItem ( ContractsID, InvoiceIDDate, InvoiceID, InvoiceLineItemDesc, InvoiceLineItemQty, InvoiceLineItemCost, Tax, ServiceCharge )" & _
    "SELECT tbl_Invoice.ContractsID, Date() AS InvoiceIDDate, Last(tbl_Invoice.InvoiceID) AS LastOfInvoiceID, ""Contract Guests for Ceremony"" AS InvoiceLineItemDesc, tbl_Contracts.MinGuaranteed, 0 AS InvoiceLineItemCost, -1 AS Tax, -1 AS ServiceCharge" & _
    "FROM tbl_Invoice INNER JOIN tbl_Contracts ON tbl_Invoice.ContractsID = tbl_Contracts.ContractsID" & _
    "GROUP BY tbl_Invoice.ContractsID, Date(), ""Contract Guests for Ceremony"",tbl_Contracts.MinGuaranteed, 0, -1, tbl_Contracts.CeremonyPPFee" & _
    "HAVING (((tbl_Invoice.ContractsID)=[Forms]![frm_Contract]![ContractsID]) AND ((tbl_Contracts.CeremonyPPFee)>0));"
            
    DoCmd.SetWarnings False
    DoCmd.RunSQL sqlDeposit1
    DoCmd.RunSQL sqlDeposit2
    DoCmd.RunSQL sqlDeposit3
    DoCmd.RunSQL sqlBalance
    DoCmd.RunSQL sqlOrigGuestCount
    DoCmd.RunSQL sqlOrigCeremonyCount
    DoCmd.SetWarnings True
    
    
    Else
    MsgBox "Payments have already been posted", vbCritical, "Payments Already Posted"
    
    
    End If
    
    
    Me.Refresh
    
    
    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    just run them as queries... don't use sql.

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    looks like you are missing spaces before your select, group by and having

    but is also the case for all your other sql selects as well

    recommend you develop the principle of always putting your spaces at the start of a line rather than at the end - easier to see if they are there

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Hi Jason,
    You need to isolate the variables, otherwise the SQL gets their literal value, here is the first one:
    Code:
    sqlDeposit1 = "INSERT INTO tbl_Invoice ( ContractsID, InvoiceDate, AmountDue, Description)" & _
    "SELECT tbl_Contracts.ContractsID, #" & [Forms]![frm_Contract]![1stDepositDue] & "# AS 1stDepositDue, " & [Forms]![frm_Contract]![1stDepositAmount] & " AS 1stDepositAmount, '1st Deposit'" & _
    " FROM tbl_Contracts WHERE(tbl_Contracts.ContractsID) = " & [Forms]![frm_Contract]![ContractsID]
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    @Gicu, RunSql should be able to process the embedded control references. CurrentDb.Execute requires concatenation.
    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.

  6. #6
    jazzy is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Nov 2021
    Posts
    77
    running them as queries fixed the issue.

    Vlad i isolated the variables but still got same error.

  7. #7
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    still got same error.
    see post #3

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    As noted, the SQL in VBA is missing spaces. This means text runs together. Do a Debug.Print sqlOrigCeremonyCount to see this.

    Your other SQL statements have the spaces.
    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.

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

Similar Threads

  1. Code works only when manually stepping through it
    By john134 in forum Programming
    Replies: 16
    Last Post: 08-15-2016, 04:41 AM
  2. Attempt to query linked tables failing
    By gnrmjd in forum Queries
    Replies: 16
    Last Post: 07-03-2014, 12:41 PM
  3. Query Failing When No Data
    By gazzieh in forum Queries
    Replies: 1
    Last Post: 12-17-2013, 09:42 AM
  4. Failing to grasp the syntax of a Union Query
    By brharrii in forum Queries
    Replies: 6
    Last Post: 05-09-2013, 11:51 AM
  5. Updateable query failing in Runtime - 2010
    By ChefContainer in forum Queries
    Replies: 1
    Last Post: 02-05-2013, 07:29 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