Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 6th, 2008, 07:20 AM
Authorized User
 
Join Date: Jun 2007
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default Create User Search Form


I have a ComboBox which has 2 columns (actual Field Names & Names I want to show as drop down), the actual field names are column1 and show as 0cm width so they arent seen by the user. I then have a TextBox so that the user can input their own search criteria. I am trying to get my search data to auto adjust the ListSearch when the user is inputting their search.

This is my code that I have, I have 2 issues.
1 when I select my search on in the ComboBox and then click on the TextBox it clears the ComboBox Values.
2 When the TextBox has data entered it doesnt search the ListBox

How can I get these to work?

Code:
Private Sub txtInputSearch_Change()
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sQRY As String
'**************************************
'    On Error GoTo Err
    Set cnn = New ADODB.Connection
    Set rs = New ADODB.Recordset
    cnn.Open "Provider=sqloledb;Data Source=CISSQL1;Initial Catalog=PODIATRY LIVE;Integrated Security=SSPI;"
    If Not IsNull(cboSearchOn) Then
        If Not IsNull(Me.txtInputSearch.Text) Then
            sQRY = _
                "SELECT " & vbCrLf & _
                "dbo.V_PAT_NHS.Patnt_RefNo_NHS_Identifier, " & vbCrLf & _
                "dbo.V_PAT_NHS.Forename, " & vbCrLf & _
                "dbo.V_PAT_NHS.Surname " & vbCrLf & _
                "FROM dbo.V_PAT_NHS " & vbCrLf & _
                "WHERE dbo.V_PAT_NHS." + Me.cboSearchOn + " LIKE '%" & Me.txtInputSearch.Text & "%' " & vbCrLf & _
                "ORDER BY dbo.V_PAT_NHS.Patnt_RefNo_NHS_Identifier "
            Me.cboSearchOn.RowSource = sQRY
            Me.lstSearch.RowSource = sQRY
        End If
        Else
            Me.cboSearchOn.SetFocus
            Me.cboSearchOn.Dropdown
    End If
'Err:
'    basError.LogError VBA.Err, VBA.Error$, "Form_frmSearch - txtInputSearch_Change()"
End Sub

 
Old November 6th, 2008, 11:22 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I don't have time to review all the code, but the first thing you should do is change this code:

"SELECT " & vbCrLf & _
                "dbo.V_PAT_NHS.Patnt_RefNo_NHS_Identifier, " & vbCrLf & _
                "dbo.V_PAT_NHS.Forename, " & vbCrLf & _
                "dbo.V_PAT_NHS.Surname " & vbCrLf & _
                "FROM dbo.V_PAT_NHS " & vbCrLf & _
                "WHERE dbo.V_PAT_NHS." + Me.cboSearchOn + " LIKE '%" & Me.txtInputSearch.Text & "%' " & vbCrLf & _
                "ORDER BY dbo.V_PAT_NHS.Patnt_RefNo_NHS_Identifier "


to this:

"SELECT " & _
"dbo.V_PAT_NHS.Patnt_RefNo_NHS_Identifier, " & _
"dbo.V_PAT_NHS.Forename, " & _
"dbo.V_PAT_NHS.Surname " & _
"FROM dbo.V_PAT_NHS " & _
"WHERE dbo.V_PAT_NHS." + Me.cboSearchOn + " LIKE '%" & Me.txtInputSearch.Text & "%' " & _
"ORDER BY dbo.V_PAT_NHS.Patnt_RefNo_NHS_Identifier "

Unless you are formatting the string for a text output, you should not have the carriage return line feed inserted. This may be ending your string prematurely, which is why there are no results. ANSI SQL will not work with those vb cursor controls.

Did any of that help?

mmcdonal

Look it up at: http://wrox.books24x7.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Create Dynamic Form; end-user adds/drops columns pkaptein1 Access 6 February 15th, 2006 03:32 AM
Create search box yami56 Access 0 August 5th, 2004 05:42 AM
Search criteria, create new worksheet Wire Excel VBA 3 March 6th, 2004 10:56 AM
Create Search Button on Access Form BKILBAN Access VBA 1 February 27th, 2004 09:01 AM
How to create a search program? kyootepuffy Classic ASP Basics 4 August 25th, 2003 08:43 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.