Results 1 to 10 of 10
  1. #1
    Stephenson is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    North West
    Posts
    110

    Report filter form using multiple comboboxes.

    Hello all,



    I'm trying to create a form, frmFilterForm to open report, JobReport and filter the records based on comboboxes in frmFilterForm. I have three fields I'd like to use as filters. cboDate, cboJobName, and cboService. Currently I'm working with the following code, but getting strange results.

    Code:
    Private Sub cmdOpenReport_Click()    
        Dim strWhere As String
        strWhere = "Service='" & Me.cboService & "'"
        DoCmd.OpenReport "JobReport", acViewPreview, , WhereCondition:=strWhere
    End Sub
    When this is run it will open the report and show the correct service text, but it will only do this once. It also replaces the Service text in Table Service with the ID number. It will continue to change that one field with any service I choose to filter with. Both frmFilterForm and JobReport are based on a query that shows all the results from EmployeeWorkLog and those records that match from tables Service and Jobs. One of the fields in EmployeeWorkLog is DateWorked.

    If you see the errors in my ways please help me out.

    Thanks for having a look.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It sounds like the combo is bound. Based on how you're using it, it shouldn't be.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Stephenson is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    North West
    Posts
    110
    pbaldy,

    You are correct, the combo was bound. I made it unbound and now when I click to open the Report it shows no records at all.

    For the combo I'm using the record source

    Code:
    SELECT Service.ID, Service.Service FROM Service;
    For the Report I'm using the record source

    Code:
    SELECT [Employees].[FirstName] & " " & [Employees].[LastName] AS EmployeeName, Jobs.JobName, Equipment.Model, Service.Service, Labor.Labor, EmployeeWorkLog.LaborHours, EmployeeWorkLog.EquipmentHours, EmployeeWorkLog.Notes, EmployeeWorkLog.DateWorked, Jobs.IDFROM Service RIGHT JOIN (Labor RIGHT JOIN (Jobs RIGHT JOIN (Equipment RIGHT JOIN (Employees RIGHT JOIN EmployeeWorkLog ON Employees.ID = EmployeeWorkLog.EmployeeID) ON Equipment.ID = EmployeeWorkLog.EquipmentID) ON Jobs.ID = EmployeeWorkLog.JobID) ON Labor.ID = EmployeeWorkLog.LaborID) ON Service.ID = EmployeeWorkLog.ServiceID
    ORDER BY [Employees].[FirstName] & " " & [Employees].[LastName];


    Do you have any suggestions for this?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Looks like you're comparing the ID to the description. Add the service ID to the report query and use that in your code.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Stephenson is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    North West
    Posts
    110
    Paul,

    Thanks for the help.

    I've added the Service ID to the reports query and changed the code to this.

    Code:
    Private Sub cmdOpenReport_Click()    
        Dim strWhere As String
        strWhere = "ServiceID='" & Me.cboService & "'"
        DoCmd.OpenReport "JobReport", acViewPreview, , WhereCondition:=strWhere
    End Sub
    Now it asks me to enter a parameter value for ServiceID. Have I put it in incorrectly in the code?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    More like the wrong field name. Based on this:

    SELECT Service.ID, Service.Service FROM Service;

    It should just be ID, or if there are more than one field with that name then Service.ID
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Stephenson is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    North West
    Posts
    110
    I've replaced ServiceID with Service.ID. It is now telling me error 3464, data type mismatched in criteria expression. Should I not have a filed name the same as the table name?

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Try

    strWhere = "Service.ID=" & Me.cboService
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    Stephenson is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    North West
    Posts
    110
    Sure enough that fixed it.

    Thank you for the great help Paul.

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 17
    Last Post: 04-29-2015, 11:48 AM
  2. Replies: 2
    Last Post: 07-03-2014, 11:32 AM
  3. Replies: 7
    Last Post: 10-13-2012, 10:53 AM
  4. Synchronize multiple comboboxes
    By phyllo in forum Forms
    Replies: 1
    Last Post: 05-01-2012, 01:49 PM
  5. Replies: 1
    Last Post: 10-08-2011, 11:15 PM

Tags for this Thread

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