Solved

Line 1: Incorrect syntax near ')' Access VBA

Posted on 2014-10-09
10
224 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now