Solved

Line 1: Incorrect syntax near ')' Access VBA

Posted on 2014-10-09
10
249 Views
Last Modified: 2014-10-09
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
Comment
Question by:Sim1980
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 10

Assisted Solution

by:Anthony Berenguel
Anthony Berenguel earned 50 total points
ID: 40371299
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
 

Author Comment

by:Sim1980
ID: 40371458
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
 
LVL 10

Expert Comment

by:Anthony Berenguel
ID: 40371474
What if you remove just line 3? Will line 1 execute successfully?
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 49

Assisted Solution

by:Gustav Brock
Gustav Brock earned 50 total points
ID: 40371733
Try with:

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

/gustav
0
 
LVL 30

Expert Comment

by:hnasr
ID: 40371803
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
 

Author Comment

by:Sim1980
ID: 40371835
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
 

Author Comment

by:Sim1980
ID: 40371840
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
 
LVL 30

Accepted Solution

by:
hnasr earned 400 total points
ID: 40371874
Run this in immediate window, at break point:
? "Price","WorkOrderItems","ItemType = 1 and WorkOrderID = " & WorkOrderID
0
 

Author Comment

by:Sim1980
ID: 40371893
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
 
LVL 30

Expert Comment

by:hnasr
ID: 40371902
Welcome!
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question