Results 1 to 8 of 8
  1. #1
    Loc is offline Novice
    Windows Vista Access 2007
    Join Date
    May 2013
    Posts
    27

    The expression is typed incorrectly. What am I doing wrong?

    You have seen this a lot but you guys have come through time and time again for me. Here is what I am doing

    I am making a query using 4 linked tables, I am using a form has start date, end date and the rest of the information is entered via combo boxes. If one combo box was left empty then I wanted to return all the data from that box.



    I am not versed in SQL so I used the design view and I first started were you needed to enter all the fields in order to get a return. Then I entered "or Like[...] Is Null" to my Criteria and access populated the rest.

    Code:
    SELECT SellTable.Date, Equipment.Department, Equipment.PrimaryMachine, Equipment.Machine, Employee.Last, Parts.PartNo, Parts.Description
    FROM Parts INNER JOIN (Equipment INNER JOIN (Employee INNER JOIN SellTable ON Employee.EmpID = SellTable.EmpID) ON Equipment.EqupID = SellTable.EqupID) ON Parts.PartID = SellTable.PartID
    WHERE (((SellTable.Date) Between [Forms]![RepairSearch].[startDate] And [Forms]![RepairSearch].[endDate]) AND 
    ((Equipment.Department)=[Forms]![RepairSearch].[cboDepartment]) AND ((Equipment.PrimaryMachine)=[Forms]![RepairSearch].[cboPrimary] Or 
    (Equipment.PrimaryMachine) Like [Forms]![RepairSearch].[cboPrimary]) AND ((Equipment.Machine)=[Forms]![RepairSearch].[cboMachine]) AND 
    ((Employee.EmpID)=[Forms]![RepairSearch].[cboEmployee] Or (Employee.EmpID) Like [Forms]![RepairSearch].[cboEmployee])) OR 
    (((SellTable.Date) Between [Forms]![RepairSearch].[startDate] And [Forms]![RepairSearch].[endDate]) AND 
    ((Equipment.PrimaryMachine)=[Forms]![RepairSearch].[cboPrimary] Or (Equipment.PrimaryMachine) Like [Forms]![RepairSearch].[cboPrimary]) AND 
    ((Equipment.Machine)=[Forms]![RepairSearch].[cboMachine]) AND ((Employee.EmpID)=[Forms]![RepairSearch].[cboEmployee] Or 
    (Employee.EmpID) Like [Forms]![RepairSearch].[cboEmployee]) AND ((([Equipment].[Department]) 
    Like [Forms]![RepairSearch].[cboDepartment]) Is Null)) OR (((SellTable.Date) Between [Forms]![RepairSearch].[startDate] And 
    [Forms]![RepairSearch].[endDate]) AND ((Equipment.Department)=[Forms]![RepairSearch].[cboDepartment]) AND 
    ((Equipment.PrimaryMachine)=[Forms]![RepairSearch].[cboPrimary] Or (Equipment.PrimaryMachine) Like [Forms]![RepairSearch].[cboPrimary]) AND 
    ((Employee.EmpID)=[Forms]![RepairSearch].[cboEmployee] Or (Employee.EmpID) Like [Forms]![RepairSearch].[cboEmployee]) AND 
    ((([Equipment].[Machine]) Like [Forms]![RepairSearch].[cboMachine]) Is Null)) OR (((SellTable.Date) Between 
    [Forms]![RepairSearch].[startDate] And [Forms]![RepairSearch].[endDate]) AND ((Equipment.PrimaryMachine)=[Forms]![RepairSearch].[cboPrimary] Or
     (Equipment.PrimaryMachine) Like [Forms]![RepairSearch].[cboPrimary]) AND ((Employee.EmpID)=[Forms]![RepairSearch].[cboEmployee] Or 
    (Employee.EmpID) Like [Forms]![RepairSearch].[cboEmployee]) AND ((([Equipment].[Department]) Like [Forms]![RepairSearch].[cboDepartment]) Is Null) AND 
    ((([Equipment].[Machine]) Like [Forms]![RepairSearch].[cboMachine]) Is Null))
    ORDER BY SellTable.Date;
    Is there am easier way to do this.
    Click image for larger version. 

Name:	EquipRepair.jpg 
Views:	23 
Size:	60.1 KB 
ID:	13317

  2. #2
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536
    Try changing the lines similar to this:

    Like [Forms]![RepairSearch].[cboMachine] Is Null

    to

    Like [Forms]![RepairSearch].[cboMachine] & "*"

  3. #3
    Loc is offline Novice
    Windows Vista Access 2007
    Join Date
    May 2013
    Posts
    27
    I have seen this but I wanted exact matches or all if left blank.

    Ex...

    I am looking for just "Dog" and I will also return "Dog Catcher" I do not want the "Dog Catcher" in my report.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    LIKE and Is Null together is nonsense. LIKE is useful only with wildcard.

    Remove LIKE and don't use wildcard.
    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
    Loc is offline Novice
    Windows Vista Access 2007
    Join Date
    May 2013
    Posts
    27
    It gave me no results by removing like and no wiled card.

  6. #6
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    I think the OP should look into MS Access sub queries and the use of Where Exists() or Where not exists()

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Did query builder put = sign in where LIKE was?

    Without the wildcard will need a value in all of the criteria inputs.

    If you use wildcard then input of "Dog" will return records with "Dog catcher".

    Alternative is instead of a parameterized query, use VBA code to dynamically construct filter string with only those controls that have inputs.

    Review:
    http://allenbrowne.com/ser-62code.html
    http://allenbrowne.com/ser-50.html
    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.

  8. #8
    Loc is offline Novice
    Windows Vista Access 2007
    Join Date
    May 2013
    Posts
    27
    My problem is I am using 4 tables to get this information, I am not sure how to combine this information and it might get complex. But what I think I am going to do is combine VBA with the query. I will make several types of querys and depending on the information they enter will result on what query will run.

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

Similar Threads

  1. Replies: 5
    Last Post: 10-03-2012, 12:41 PM
  2. Replies: 2
    Last Post: 06-07-2012, 02:59 PM
  3. Replies: 1
    Last Post: 05-24-2012, 12:34 PM
  4. This expression is typed incorrectly
    By Ray67 in forum Queries
    Replies: 9
    Last Post: 01-03-2012, 12:53 PM
  5. Replies: 3
    Last Post: 03-31-2011, 11:07 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