Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 6th, 2008, 07:20 AM
Authorized User
 
Join Date: Jun 2007
Location: , , .
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

Reply With Quote
  #2 (permalink)  
Old November 6th, 2008, 11:22 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:08 AM.


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