Results 1 to 6 of 6
  1. #1
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276

    Syntax error (missing operator)

    When I run the following code I get SYNTAX ERROR (MISSING OPERATOR) In a query expression 'Delivered To Party'

    How Do I Fix The Following

    Please note:
    GP Dialog is a query
    Purchase Description is a field
    Delivered To Party is a field


    Private Sub CboD2Pty_AfterUpdate()
    Dim strSource As String


    strSource = "SELECT Delivered To Party " & _
    "FROM GP Dialog " & _
    "WHERE Purchase Description = '" & Me.CboD2Pty & "' ORDER BY Delivered To Party"
    Me.cboPdiscr.RowSource = strSource
    Me.cboPdiscr = vbNullString
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Field and table names have spaces. Enclose them in []. Advise to avoid spaces and special characters/punctuation (underscore is exception) in naming convention. Better would be Delivered_To_Party or DeliveredToParty.

    Why use code to set RowSource? Why not just put static SQL statement directly in the RowSource property?

    SELECT [Delivered To Party] FROM [GP Dialog] WHERE [Purchase Description] = [CboD2Pty] ORDER BY [Delivered To Party];

    Need code to requery the RowSource. Suggest the combobox GotFocus event:

    Me.CboD2Pty.Requery
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    thx for the help I got the spaces issue fixed but a bigger problem came up

    I am using the following code. This time I am using TABLE: Purchases


    Private Sub CboPtyNme_AfterUpdate()
    Dim strSource As String
    strSource = "SELECT [Purchase Description] " & _
    "FROM Purchases " & _
    "WHERE [Delivered To Party] = '" & Me.CboPtyNme & "' ORDER BY [Purchase Description]"
    Me.Cboitems.RowSource = strSource
    Me.Cboitems = vbNullString
    End Sub



    When I select the Customer Title in CboPtyNme & Item Description in Cboitems I am getting multiple items in Cboitems


    Click image for larger version. 

Name:	POPUP.jpg 
Views:	6 
Size:	140.9 KB 
ID:	18224

    where am I making a mistake

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Use DISTINCT keyword:

    SELECT DISTINCT ...

    These controls are UNBOUND and used just to input filter criteria, not to enter/edit data into record?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I really hate changing a combo box row source "on-the-fly".
    Set the combo box row source once in design view - then you are down to two lines.
    Code:
    Private Sub CboPtyNme_AfterUpdate()
      Me.Cboitems.Requery
      Me.Cboitems = vbNullString
    End Sub
    I know there are lots of examples demonstrating the change row source technique, but (to me) it is like changing the form recordsource every time you want to filter records.

    OK, I'm off my soap box.....

  6. #6
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    Thanks for the help. Have fixed it as follows


    Private Sub CboPtyNme_AfterUpdate()
    Dim strSource As String
    strSource = "SELECT DISTINCT [Purchase Description] " & _
    "FROM Purchases " & _
    "WHERE [Delivered To Party] = '" & Me.CboPtyNme & "' ORDER BY [Purchase Description]"
    Me.Cboitems.RowSource = strSource
    Me.Cboitems = vbNullString
    End Sub






    Private Sub cmdOpenReportSingle_Click()
    On Error GoTo Err_Handler

    Const REPORTNAME = "Delivered2Party"
    Const MESSAGETEXT = "No Item Selected."
    Dim strCriteria As String

    ' build string expression to filter report
    ' to selected customer
    strCriteria = "[Delivered To Party] = """ & Me.CboPtyNme & """"


    ' make sure a customer is selected
    If Not IsNull(Me.CboPtyNme) Then
    ' open report filtered to selected customer
    DoCmd.OpenReport REPORTNAME, _
    View:=acViewPreview, _
    WhereCondition:=strCriteria
    Else
    MsgBox MESSAGETEXT, vbExclamation, "Invalid operation"
    End If

    Exit_Here:
    Exit Sub

    Err_Handler:
    MsgBox Err.Description, vbExclamation, "Error"
    Resume Exit_Here

    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 02-17-2014, 10:27 AM
  2. Replies: 9
    Last Post: 01-22-2013, 04:23 PM
  3. Replies: 6
    Last Post: 05-30-2012, 12:32 PM
  4. Syntax error missing operator(3075)
    By parisienne in forum Programming
    Replies: 1
    Last Post: 04-07-2011, 02:29 PM
  5. Syntax Error...missing operator
    By jgelpi16 in forum Programming
    Replies: 14
    Last Post: 09-09-2010, 11:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums