Results 1 to 8 of 8
  1. #1
    ShawnCartwright is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    10

    Problem with displaying search results in subform

    Hi there,

    Im new to this site. Im hoping you can help, Ive tried for about a week now and close to tears lol. Im trying to get the search to pull information from textboxes and populate the form with the information. Ive had success in other databases but this one does seem to want to work and ive gone to the edge of screaming. Perhaps you can help please?

    Private Sub cmdSearch_Click()
    On Error GoTo errr
    Me.tblsubCustomerInformation.Form.RecordSource = "SELECT * FROM tblCustomerInformation " & BuildFilter
    Me.tblsubCustomerInformation.Requery
    Exit Sub
    errr:
    MsgBox Err.Description
    End Sub


    Private Function BuildFilter() As Variant


    Dim varWhere As Variant


    Dim CustomerNumber As String
    Dim CustomerFirstName As String
    Dim CustomerAddress1 As String
    Dim CustomerPhone As String


    CustomerNumber = """"
    CustomerFirstName = """"
    CustomerAddress1 = """"
    CustomerPhone = """"


    varWhere = Null


    If Me.txtCustomerNumber > "" Then
    varWhere = varWhere & "[CustomerNumber] like " & CustomerNumber & Me.txtCustomerNumber & CustomerNumber & " AND "
    End If


    If Me.txtCustomerFirstName > "" Then
    varWhere = varWhere & "[CustomerFirstName] like " & CustomerFirstName & Me.txtCustomerFirstName & CustomerFirstName & " AND "
    End If


    If Me.txtCustomerAddress1 > "" Then
    varWhere = varWhere & "[CustomerAddress1] like " & CustomerAddress1 & Me.txtCustomerAddress1 & CustomerAddress1 & " AND "
    End If


    If Me.txtCustomerPhone > "" Then
    varWhere = varWhere & "[CustomerPhone] like " & CustomerPhone & Me.txtCustomerPhone & CustomerPhone & " AND "
    End If




    If IsNull(varWhere) Then
    varWhere = ""
    Else
    varWhere = "WHERE " & varWhere
    If Right(varWhere, 5) = " AND " Then
    varWhere = Left(varWhere, Len(varWhere) - 5)
    End If
    End If
    BuildFilter = varWhere
    End Function

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You haven't said what the problem is, but we can start here and find out what the function is returning:

    BaldyWeb-Immediate window
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ShawnCartwright is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    10
    sorry lol. Its not populating the subform with the information I input in the textboxes. Its just going blank or bring up the first entry in the table only.

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What's the result of the Debug.Print?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    ShawnCartwright is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    10
    Quote Originally Posted by pbaldy View Post
    What's the result of the Debug.Print?
    Nothing. :/

  6. #6
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Presuming you used it correctly, that would mean the function isn't returning anything. Try setting a breakpoint and following the code so you can see what the variables contain at each step of the process.

    http://www.baldyweb.com/Debugging.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    ShawnCartwright is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    10
    Quote Originally Posted by pbaldy View Post
    Presuming you used it correctly, that would mean the function isn't returning anything. Try setting a breakpoint and following the code so you can see what the variables contain at each step of the process.

    http://www.baldyweb.com/Debugging.htm
    database was corrupt had to import it all into a fresh one. Thank you for your help.

  8. #8
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Glad you got it sorted out.
    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: 7
    Last Post: 08-08-2012, 03:28 PM
  2. Search Box Requerying Subform problem
    By cbh35711 in forum Access
    Replies: 1
    Last Post: 03-30-2012, 09:37 AM
  3. Displaying query results in form
    By celito in forum Access
    Replies: 2
    Last Post: 08-27-2011, 09:14 AM
  4. Replies: 0
    Last Post: 03-31-2010, 07:52 AM
  5. Replies: 4
    Last Post: 01-11-2010, 11:41 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