Results 1 to 3 of 3
  1. #1
    Coffee is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jul 2011

    Query search wont display null fields

    Hi, i have a query to search a form input value for a specific username. i am using the Like * function to select all if no username has been entered or if one is entered then it passes that into the sql query string instead. the problem with this is that the LIKE function doesnt return empty fields, only the fields with data in them. is there a way around this?? so it displays empty username records aswell as ones with the same username. code is below i am using, it must be able to fit in the null check and insert into the sql string. thanks

    Private Sub bob_Click()

    On Error GoTo Err_bob_Click

    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim strsql As String
    Dim strUserSearch As String

    Set db = CurrentDb
    Set qdf = db.QueryDefs("fullSearch")

    If IsNull(Me.userSearch.value) Then
    strUserSearch = " Like '*' "
    strUserSearch = "='" & Me.userSearch.value & "' "
    End If

    strsql = "SELECT dbo_HistoricalReport.*" & _
    "FROM dbo_HistoricalReport " & _
    "WHERE dbo_HistoricalReport.UserName" & strUserSearch & _

    MsgBox strsql
    qdf.SQL = strsql

    DoCmd.OpenQuery "fullSearch"

    Set qdf = Nothing
    Set db = Nothing

    Exit Sub

    MsgBox Err.Description
    Resume Exit_bob_Click

    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Nevada, USA
    Try adding

    OR UserName Is Null
    Paul (wino moderator)
    MS Access MVP 2007-2019

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    OR isnull(username)
    is another option

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

Similar Threads

  1. Display Fields in Search Form
    By j2curtis64 in forum Forms
    Replies: 1
    Last Post: 07-18-2011, 01:37 PM
  2. make query fields not display if null data
    By rivereridanus in forum Queries
    Replies: 1
    Last Post: 07-05-2011, 08:19 AM
  3. Subform records wont display
    By taylorosso in forum Forms
    Replies: 10
    Last Post: 10-09-2009, 08:59 AM
  4. drop down wont display
    By gromit95 in forum Database Design
    Replies: 3
    Last Post: 10-21-2008, 11:12 AM
  5. Query to Display Tables & Fields
    By foxerator in forum Queries
    Replies: 0
    Last Post: 04-24-2008, 09:57 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 - Senior Forums