Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2004
    Posts
    51

    Unanswered: No results displayed

    I have a form where i hve two unbound text boxes, and one search button. One box is keywork and the other is presenters name, if i put something in keywork only i get the proper results and if i put something in presenters name i get proper results but if i put something in both i gets no results but i wanted both too work at the same time. Here is the code i have for the button anyone see anything wrong?

    Private Sub cmdSearch_Click()
    On Error GoTo Err_cmdSearch_Click

    Dim stDocName As String
    Dim stLinkCriteria As String
    Dim test As String

    test = Me![txtPresentersname] & [txtKeyword]

    stDocName = "frmPresenters"


    stLinkCriteria = "[Keyword]&[Presenters Name]LIKE" & " '" & "*" & test & "*" & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Exit_cmdSearch_Click:
    Exit Sub

    Err_cmdSearch_Click:
    MsgBox Err.Description
    Resume Exit_cmdSearch_Click


    Jason

  2. #2
    Join Date
    Mar 2004
    Location
    www.scirocco.ca
    Posts
    346
    Try this instead:

    Private Sub cmdSearch_Click()
    On Error GoTo Err_cmdSearch_Click

    Dim stDocName As String
    Dim stLinkCriteria As String
    Dim test As String
    Dim test1 As String

    test = Me![txtKeyword]
    test1 = Me![txtPresentersname]

    stDocName = "frmPresenters"

    'USE Either AND or OR depending on what you want

    stLinkCriteria = "[Keyword] LIKE" & " '" & "*" & test & "*" & "' AND [Presentersname] LIKE" & " '" & "*" & test1 & "*" & "'"

    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Exit_cmdSearch_Click:
    Exit Sub

    Err_cmdSearch_Click:
    MsgBox Err.Description
    Resume Exit_cmdSearch_Click
    http://www.scirocco.ca/images/banner...occobanner.gif

    Download for FREE the ADO/DAO Data Controls that makes life EASIER developing database applications in: VB, FoxPro, Access, VC++, .NET etc... Navigate, Add New, Delete, Update, Search, Undo and Save your changes. Supports Disconnected Recordsets and Transactions!

    Or try our Ask An Expert service to answer any of your questions!

  3. #3
    Join Date
    Mar 2004
    Posts
    51

    Smile

    Thanks SCIROCCO:

    Thanks for the help, when i searches and puts nothing in one box it says invalid use of null, is that because i am not putting nothing in the text box?

    If so is there a way to put nothing in the text box and only search on one criteria? but leave the code the same so if desired search on both if desired?

    What i am trying to say, if a person wanted to would they be able to search either of the two or just one text box?

    Jason

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Hi Jason

    An empty text box contains a Null value. a VB text string cannot be null - it's equivelent is a zero length string ("").

    if you change the variable assignments to:

    test = nz(Me![txtKeyword])
    test1 = nz(Me![txtPresentersname])

    the nz function changes a null to the default value for a data type (in this case a zero length string). Worth looking up in help as it can be very useful, both as preventing errors like this and also simplifying your code (without it you would use a lot more if statements).
    This should do what you want, so long as your PresentersName and Keyword fields contain values for all records.
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •