Results 1 to 4 of 4
  1. #1
    aligahk06 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Posts
    94

    Search based on combo box.

    I changed text box to combo box. the name of combox is combo76 .while selecting the list from combo box and toDate and fromDate then clicking on search command it doesn't give the desired result.


    So please modify the code based on combo box, name combo76.

    Any modification below code based on combo box.
    Private Sub Search_Click()
    'i want to click search command button after input from date and to date field value then it return all corresponding records.
    Dim strCriteria As String, task As String
    Me.Refresh
    If IsNull(Me.FromDate) Or IsNull(Me.ToDate) Then
    MsgBox " Enter the Date Range", vbInformation, "Date Range required "
    Me.FromDate.SetFocus
    Exit Sub
    End If
    'if costCode is required in the search, uncomment the next 5 lines
    '' If IsNull(Me.costCode) Then
    '' MsgBox "costCode is required", vbInformation, "costCode required"
    '' Me.costCode.SetFocus
    '' Exit Sub
    '' End If
    If Not IsNull(Me.costCode) Then
    strCriteria = "CCode ='" & Me.costCode & "' AND "
    End If
    strCriteria = strCriteria & "[dDate]>= #" & Me.FromDate & "# And [dDate] <= #" & Me.ToDate & "#"
    task = " select * from woPR where " & strCriteria & " order By [dDate]"
    'Debug.Print task

    Me.RecordSource = task
    If Me.RecordsetClone.RecordCount = 0 Then
    MsgBox "no match"
    Me.RecordSource = "select * from woPR"
    End If
    End Sub

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    I changed text box to combo box.
    What text box.
    What is the name of the Control/field that the combo box is to be compared to.
    Is the data in the Control/field text or numeric.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I agree that there is not enough info to give an answer. Maybe you would post your dB with any sensitive info changed.


    Quote Originally Posted by aligahk06 View Post
    ........while selecting the list from combo box
    What is the row source for the combo box "combo76". Btw, it is worth it to take the time to give objects meaningful names... and it sure helps when troubleshooting.


    Quote Originally Posted by aligahk06 View Post
    ..........and toDate and fromDate then clicking on search command it doesn't give the desired result.
    You need to be more specific.
    What are the results?
    What results do you expect?


    Why do you keep changing the form record source instead of just setting a filter?




    So now you have 3 posts on this piece of code. You should really try and stick with one thread until it is solved (if a solution is possible).

  4. #4
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    See previous thread marked SOLVED.
    https://www.accessforums.net/showthread.php?t=81365
    Last edited by davegri; 08-06-2020 at 09:29 AM.

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

Similar Threads

  1. Dynamic Combo Box Based on a Search Box
    By LonghronJ in forum Modules
    Replies: 4
    Last Post: 06-27-2019, 10:10 AM
  2. Replies: 5
    Last Post: 09-22-2016, 08:42 AM
  3. Search Query Based on Multiple Combo / Text Boxes
    By ItsJustRey in forum Queries
    Replies: 5
    Last Post: 07-20-2016, 02:04 PM
  4. Replies: 3
    Last Post: 01-04-2015, 06:09 PM
  5. Replies: 7
    Last Post: 08-08-2012, 03:28 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