Solved

Extra ) in SQL Expression

Posted on 2008-06-13
2
615 Views
Last Modified: 2013-12-25
I've used an SQL query in some VBA code I've written.  I don't know much about SQL so I kinda pieced it together with help from the Internet.  Now, when the query is run I get the error message "Runtime Error '3075': Extra ) in query expression '(((tblDeployment.UpdateID)=))'."

I've included the whole code section so that you can see what I'm doing.  I've tried removing a close bracket from before and after the equals sign but then I just get a syntax error when I run the query.

What am I doing wrong?
If Me.Dirty = False Then
 
    'This section counts the number of servers to which the update has been deployed
    Dim rs As DAO.Recordset
    Dim sSQL As String
 
    sSQL = "SELECT Count(tblDeployment.Computer) AS CountOfComputer "
    sSQL = sSQL & "FROM tlkComputers INNER JOIN tblDeployment ON tlkComputers.Computer=tblDeployment.Computer "
    sSQL = sSQL & "WHERE (((tblDeployment.DeploymentType) = 'Live') And ((tlkComputers.Group) = 'Servers')) "
    sSQL = sSQL & "GROUP BY tblDeployment.UpdateID HAVING (((tblDeployment.UpdateID)= " & Forms!frmUpdatesWrapper!frmUpdates!txtUpdateID & "));"
 
    Debug.Print sSQL
 
    Set rs = CurrentDb.OpenRecordset(sSQL)
 
    If Not (rs.BOF And rs.EOF) Then
        Me.txtNumberDeployed = rs!CountOfComputer
    Else
    'your query did not return any records.
    End If
 
    Set rs = Nothing
 
End If

Open in new window

0
Comment
Question by:WPHIT
2 Comments
 
LVL 16

Accepted Solution

by:
Robin earned 250 total points
ID: 21777060
Your query fails, when Forms!frmUpdatesWrapper!frmUpdates!txtUpdateID is empty.

You could check for that or replace
Forms!frmUpdatesWrapper!frmUpdates!txtUpdateID
with
NZ(Forms!frmUpdatesWrapper!frmUpdates!txtUpdateID, -1)

and -1 being a non-existing id.
0
 

Author Comment

by:WPHIT
ID: 21777193
Excellent, thank you, that's done it.  I just added another IF statement to prevent the SQL query being run if the UpdateID field is blank.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Query Syntax error after > 11 39
Access syntax 1 33
Runtime Error -2147467259 (80004005) 7 40
access query - filter field for particular number format 3 25
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

685 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