Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 277
  • Last Modified:

Line 1: Incorrect syntax near ')' Access VBA

Hi all.

I get the following error: Line 1: Incorrect syntax near ')'

Below is my code. I've narrowed the error down to line:
calculatedfreight = Round(DSum("Price","WorkOrderItems","ItemType = 1 and WorkOrderID = " & WorkOrderID) * .024, 2)

Private Sub DeleteRecord_Click()

Dim rs1 As ADODB.Recordset
Dim DeletedItemID As Long

DeletedItemID = Me!ItemID

DoCmd.DoMenuitem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuitem acFormBar, acEditMenu, 6, , acMenuVer70

DoCmd.RunSQL "DELETE FROM dbo.WorkOrderItems WHERE ParentItemID = & DeletedItemID

Dim calculatedfreight as Currency

calculatedfreight = Round(DSum("Price","WorkOrderItems","ItemType = 1 and WorkOrderID = " & WorkOrderID) * .024, 2)

DoCmd.RunSQL "UPDATE dbo.WorkOrders SET Freight = " & calculatedfreight & " WHERE OrderID = " & WorkOrderID

End Sub

Open in new window


What am I doing wrong? Thank you in advance.
0
Sim1980
Asked:
Sim1980
  • 4
  • 3
  • 2
  • +1
3 Solutions
 
Anthony BerenguelCommented:
See line 11.
Private Sub DeleteRecord_Click()

	Dim rs1 As ADODB.Recordset
	Dim DeletedItemID As Long

	DeletedItemID = Me!ItemID

	DoCmd.DoMenuitem acFormBar, acEditMenu, 8, , acMenuVer70
	DoCmd.DoMenuitem acFormBar, acEditMenu, 6, , acMenuVer70

	DoCmd.RunSQL "DELETE FROM dbo.WorkOrderItems WHERE ParentItemID = " & DeletedItemID ' you were missing the closing quotation symbol before the ampersand. 

	Dim calculatedfreight as Currency

	calculatedfreight = Round(DSum("Price","WorkOrderItems","ItemType = 1 and WorkOrderID = " & WorkOrderID) * .024, 2)

	DoCmd.RunSQL "UPDATE dbo.WorkOrders SET Freight = " & calculatedfreight & " WHERE OrderID = " & WorkOrderID

	End Sub

Open in new window

0
 
Sim1980Author Commented:
Added the missing closing quotation symbol and I still get the same error.

When I remove the lines:

calculatedfreight = Round(DSum("Price","WorkOrderItems","ItemType = 1 and WorkOrderID = " & WorkOrderID) * .024, 2)

	DoCmd.RunSQL "UPDATE dbo.WorkOrders SET Freight = " & calculatedfreight & " WHERE OrderID = " & WorkOrderID

Open in new window


I don't get the error.
0
 
Anthony BerenguelCommented:
What if you remove just line 3? Will line 1 execute successfully?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Gustav BrockCIOCommented:
Try with:

calculatedfreight = Round(DSum("Price","WorkOrderItems","ItemType = 1 and WorkOrderID = " & WorkOrderID & "") * .024, 2)

/gustav
0
 
hnasrCommented:
What are you trying to do?

In code, there are recordset, delete, and update statements.

This line looks fine:
calculatedfreight = Round(DSum("Price","WorkOrderItems","ItemType = 1 and WorkOrderID = " & WorkOrderID) * .024, 2)

But try to check it by setting a break point at the line.
Then in immediate window check:
?DSum("Price","WorkOrderItems","ItemType = 1 and WorkOrderID = " & WorkOrderID)
0
 
Sim1980Author Commented:
Anthony: I removed line 3 and still get the same error

Gustav: I added your code and still get the same error

hnasr: I set a break point at the line, in the immediate window I type ? and the line of code.
I got the following error message: Run-time error '170': Line 1: Incorrect syntax near ')'.
0
 
Sim1980Author Commented:
It should be noted, if I place that line of code before the DELETE statement, I do not get an error and it correctly  updates the calculatedfreight.
0
 
hnasrCommented:
Run this in immediate window, at break point:
? "Price","WorkOrderItems","ItemType = 1 and WorkOrderID = " & WorkOrderID
0
 
Sim1980Author Commented:
That was it hnasr !

When I ran you last code in the immediate window, it showed WorkOrderID as null.

I made sure the WorkOrderID was on the form and used Me.WorkOrderID instead and it solved the problem.

Thanks!
0
 
hnasrCommented:
Welcome!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now