R
Regan via AccessMonster.com
Hi, don't know why this isn't working, i copied the SQL from the immediate
window and chucked it in SQL view and it runs fine. Just don't know why it
isn't working in VBA
Any help would be appreiacted( i know i can't spell)
Private Sub CmdAutoPop_Click()
On Error GoTo ProcErr
Dim IntInvoiceID As Integer
Dim StrSQLI As String
IntInvoiceID = Forms!frmcreateInv!txtInvoiceID
StrSQLI = "INSERT INTO tblinvoicedetails(InvoiceID, InvCatagory, amount) " &
_
"SELECT """ & IntInvoiceID & """ AS invoiceID, tblCodes.InvCatagory,
Format(Sum(tbltimesheet.units/10*IIf(tblcodes.chargetype=""code""
,tblcodes.chargerate,tblemployconf.chargeoutrate)),'Currency') AS
TotalPerCata " & _
"FROM tblCodes INNER JOIN (tblEmployConf INNER JOIN tblTimesheet ON
tblEmployConf.EmployConfID = tblTimesheet.EmployconfID) ON tblCodes.CodeID =
tblTimesheet.CodeID " & _
"WHERE (((tblCodes.InvCatagory) <> """") And ((tblTimesheet.FileID)
= [Forms]![frmcreateinv]![txtFileID]) And ((tblTimesheet.EntryDate) >= [Forms]
![frmcreateinv]![txtDateFrom] And (tblTimesheet.EntryDate) <= [Forms]!
[frmcreateinv]![txtDateTo])) " & _
"GROUP BY tblCodes.InvCatagory;"
Debug.Print StrSQLI
CurrentDb.Execute StrSQLI, dbFailOnError
DoCmd.RunCommand acCmdRefresh
ProcExit:
Exit Sub
ProcErr:
MsgBox "Error " & Err.Number & "(" & Err.Description & ")"
Resume ProcExit
window and chucked it in SQL view and it runs fine. Just don't know why it
isn't working in VBA
Any help would be appreiacted( i know i can't spell)
Private Sub CmdAutoPop_Click()
On Error GoTo ProcErr
Dim IntInvoiceID As Integer
Dim StrSQLI As String
IntInvoiceID = Forms!frmcreateInv!txtInvoiceID
StrSQLI = "INSERT INTO tblinvoicedetails(InvoiceID, InvCatagory, amount) " &
_
"SELECT """ & IntInvoiceID & """ AS invoiceID, tblCodes.InvCatagory,
Format(Sum(tbltimesheet.units/10*IIf(tblcodes.chargetype=""code""
,tblcodes.chargerate,tblemployconf.chargeoutrate)),'Currency') AS
TotalPerCata " & _
"FROM tblCodes INNER JOIN (tblEmployConf INNER JOIN tblTimesheet ON
tblEmployConf.EmployConfID = tblTimesheet.EmployconfID) ON tblCodes.CodeID =
tblTimesheet.CodeID " & _
"WHERE (((tblCodes.InvCatagory) <> """") And ((tblTimesheet.FileID)
= [Forms]![frmcreateinv]![txtFileID]) And ((tblTimesheet.EntryDate) >= [Forms]
![frmcreateinv]![txtDateFrom] And (tblTimesheet.EntryDate) <= [Forms]!
[frmcreateinv]![txtDateTo])) " & _
"GROUP BY tblCodes.InvCatagory;"
Debug.Print StrSQLI
CurrentDb.Execute StrSQLI, dbFailOnError
DoCmd.RunCommand acCmdRefresh
ProcExit:
Exit Sub
ProcErr:
MsgBox "Error " & Err.Number & "(" & Err.Description & ")"
Resume ProcExit