Results 1 to 6 of 6
  1. #1
    PeterS is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Posts
    45

    Using an unbound Combo Box and two unbound Text boxes on a Form to search a Query

    Hi



    I have a Form that I use to search a query that is simply a Start Date and an End Date.

    In the Query criteria I have the following;
    [Forms]![frmTechnicianService]![txtStartDate] And [Forms]![frmTechnicianService]![txtEndDate]


    This works very well. When I enter the start date and the end date and hit the button the query runs 100% and opens the desired report.

    MY PROBLEM

    I would like to add a Combo Box to my Form so that I can drill down my report. I want to use a Combo Box to select a technician's name and then enter a start date and an end date.

    This is my SQL statement

    SELECT TechnicianTbl.Technician, ForkliftServiceTbl.ServiceDate, ForkliftTbl.ForkliftNumber, ForkliftServiceTbl.ServiceDetails
    FROM TechnicianTbl INNER JOIN (ForkliftTbl INNER JOIN ForkliftServiceTbl ON ForkliftTbl.ForkliftID_Pk = ForkliftServiceTbl.ForkliftID_Fk) ON TechnicianTbl.[TechnicianID-Pk] = ForkliftServiceTbl.Technician
    WHERE (((TechnicianTbl.Technician)=Forms!frmTechnicianSe rvice!cboTechnician) And ((ForkliftServiceTbl.ServiceDate) Between Forms!frmTechnicianService!txtStartDate And Forms!frmTechnicianService!txtEndDate));

    As soon as I add the Combo Box the report will not populate and it is blank. Both Text Boxes and the Combo Box are Unbound.

    Please can you tell me where I am going wrong?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    make the form use a query that shows all records.
    then when the items are filled FILTER the results, but you must check the controls to see what is used:

    build the 'where' clause by cycling thru all the controls....
    it executes after a find button CLICK event
    if null, ignore.
    if not, apply.


    Code:
    '----------------
    sub btnFilter_click()
    '----------------
    dim sWhere as string 
    
    
    sWhere = "1=1"
    if not IsNUll(cboST) then sWhere = sWhere & " and [State]='" & cboST & "'"
    if not IsNUll(cboCity) then sWhere = sWhere & " and [city]='" & cboCity & "'"
    if not IsNUll(cboZip) then sWhere = sWhere & " and [ZipCode]='" & cboZip & "'"
    
    
    If sWhere = "1=1" Then
      Me.FilterOn = False
    Else
      Me.Filter = sWhere
      Me.FilterOn = True
    End If
    end sub

  3. #3
    PeterS is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Posts
    45
    Thanks ranman
    I have to wrap my head around that one. I am a newbie to SQL

    Where would I put the code you wrote?

    What do you mean by I need to cycle through all the controls and how would I do that?

  4. #4
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Bind your report to a query with this SQL definition:

    Code:
    SELECT TechnicianTbl.Technician, ForkliftServiceTbl.ServiceDate, ForkliftTbl.ForkliftNumber, ForkliftServiceTbl.ServiceDetails FROM TechnicianTbl 
    INNER JOIN (ForkliftTbl INNER JOIN ForkliftServiceTbl  ON ForkliftTbl.ForkliftID_Pk = ForkliftServiceTbl.ForkliftID_Fk) 
    ON  TechnicianTbl.[TechnicianID-Pk] = ForkliftServiceTbl.Technician
    Then, on OnClick event of a command button in the form that you refer, insert those lines of code:

    Code:
        
        Dim strWHERE As String
    
        strWHERE = "([TechnicianTbl].[Technician]=" & Me.cboTechnician _
                 & ") AND ([ForkliftServiceTbl].[ServiceDate]" _
                 & "BETWEEN ((#" & Me.txtStartDate & "#" _
                 & ") AND (#" & Me.txtEndDate & "#)));"
                 
        Debug.Print strWHERE
        DoCmd.OpenReport "MyReport", acViewPreview, , strWHERE
    Replace the "MyReport" with the real name of your report, choose a Technician, insert the start date and the end date, hit the button and let me know if it works.

    Good luck with your project!

  5. #5
    PeterS is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Posts
    45
    Hi accesstos

    Thank you for your help. Not sure if it is because of my incompetance but I get the following error when entering the code:

    Compile Error! Method or data member not found.

    Private Sub Technician_Click()
    Dim strWHERE As String
    strWHERE = "([TechnicianTbl].[Technician]=" & Me.cboTechnician _
    & ") AND ([ForkliftServiceTbl].[ServiceDate]" _
    & "BETWEEN ((#" & Me.txtStartDate & "#" _
    & ") AND (#" & Me.txtEndDate & "#)));"

    Debug.Print strWHERE
    DoCmd.OpenReport "MyReport", acViewPreview, , strWHERE
    End Sub

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    See if this tutorial helps http://allenbrowne.com/ser-62.html

    Is Technician a number or text field? If it is text, need apostrophe delimiters.

    Need a space in front of BETWEEN. Remove the semi-colon.

    strWHERE = "[TechnicianTbl].[Technician]=" & Me.cboTechnician _
    & " AND [ForkliftServiceTbl].[ServiceDate]" _
    & " BETWEEN #" & Me.txtStartDate & "# AND #" & Me.txtEndDate & "#"
    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.

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

Similar Threads

  1. Replies: 9
    Last Post: 11-06-2014, 01:15 PM
  2. Replies: 9
    Last Post: 11-05-2014, 09:23 AM
  3. Replies: 9
    Last Post: 01-09-2014, 02:58 PM
  4. Using Unbound text boxes
    By rbiggs in forum Reports
    Replies: 4
    Last Post: 08-16-2011, 04:05 PM
  5. Unbound Text boxes
    By kyleg222 in forum Forms
    Replies: 2
    Last Post: 08-02-2011, 12:53 PM

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