473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Need Help with a Search Form in Access 2003

418 256MB
I am working on a database on my CD collection using Access 2003. Some of the table structures are given below.

Table 1 tblMusicCategory

Field 1: MusicCategoryID - Auto Number (PK)
Field 2: MusicCategory - text
Field 3: MusicCategoryAbbv - text

Table 2 tblArtists
Field 1 ArtistID - Auto Number (PK)
Field 2 ArtistName - text
Field 3 ArtistAbbv – text

Table 4 tbType

Field 1: TypeID - Auto Number (PK)
Field 2: Type - text


Table 4 tblCDDetails

Field 1: RecordingD - Auto Number (PK)
Field 2: SerialNumber - Text
Field 3: RecordingTitle - Text
Field 4: MusicCategoryID - FK
Field 5: ArtistID – FK
Field 6: TypeID – FK
Field7: LanguageID – FK

To enter CDs I use a form called frmCDDetails which is based on tblCDDetails .

I am trying to create a Search Form which can help me check whether a CD is already entered or not, eg.. To do this, I created a form called frmSearch where I have several “unbound” text boxes to enter search criteria (Artist name or Category or Title or Type etc). I added a ListBox to display the findings and a command button cmdFind to execute the search engine.

I added the following CODES to the “Click” event of the cmdFind button. But when I click on FIND I get the four blank columns with no data in it. I entered an Artist’s name or a CD Title that I know exist in the database. Still I get foul blank columns.

What am I doing wrong? Can someone please help? Please e-mail me with any questions: ** address removed as per rules **. Many thanks in advance.

Here are the CODES.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdFind_Click()
  2.     Dim strSQL As String
  3.     Dim Criteria As String
  4.  
  5.     strSQL = "SELECT RecordingID as ID, RecordingTitle, CategoryID, TypeID, RecordingArtistID" & _
  6.              "FROM tblCDDetails WHERE "
  7.     If IsNull(Me.RecordingTitle) And _
  8.        IsNull(Me.MusicCategoryID) And _
  9.        IsNull(Me.TypeID) And _
  10.        IsNull(Me.RecordingArtistID) Then
  11.             MsgBox "Must Enter at least one value in " & _
  12.                    "order to search database.", vbOKOnly
  13.     Else
  14.         If Not IsNull(Me.RecordingTitle) Then
  15.             If Len(Criteria) > 0 Then
  16.                 Criteria = Criteria & " AND RecordingTitle = '" & Me.RecordingTitle & "'"
  17.             Else
  18.                 Criteria = Criteria & "RecordingTitle = '" & Me.RecordingTitle & "'"
  19.             End If
  20.         End If
  21.         If Not IsNull(Me.MusicCategoryID) Then
  22.             If Len(Criteria) > 0 Then
  23.                 Criteria = Criteria & " AND MusicCategoryID = '" & Me.MusicCategoryID & "'"
  24.             Else
  25.                 Criteria = Criteria & "MusicCategoryID = '" & Me.MusicCategoryID & "'"
  26.             End If
  27.         End If
  28.         If Not IsNull(Me.TypeID) Then
  29.             If Len(Criteria) > 0 Then
  30.                 Criteria = Criteria & " AND TypeID = '" & Me.TypeID & "'"
  31.             Else
  32.                 Criteria = Criteria & "TypeID = '" & Me.TypeID & "'"
  33.             End If
  34.         End If
  35.         If Not IsNull(Me.RecordingArtistID) Then
  36.             If Len(Criteria) > 0 Then
  37.                 Criteria = Criteria & " AND RecordingArtistID = '" & Me.RecordingArtistID & "'"
  38.             Else
  39.                 Criteria = Criteria & "RecordingArtistID = '" & Me.RecordingArtistID & "'"
  40.             End If
  41.         End If
  42.  
  43.         strSQL = strSQL & Criteria
  44.         Me.ResultList.ColumnCount = 4
  45.         Me.ResultList.BoundColumn = 1
  46.         Me.ResultList.ColumnHeads = True
  47.         Me.ResultList.ColumnWidths = "720;2160;1440;1440"
  48.         Me.ResultList.RowSourceType = "Table/Query"
  49.         Me.ResultList.RowSource = strSQL
  50.         Me.ResultList.Requery
  51.     End If
  52. End Sub
  53.  
Aug 27 '08 #1
2 2271
Hi. I didn't notice anything wrong right away, but I'll tell you how I usually debug these types of problems.
Set a breakpoint in the _Click event after the entire string is composed. The first thing I would do is when the breakpoint is hit, go to the immediate window and print out the contents of the string:
Expand|Select|Wrap|Line Numbers
  1. ? sqlString
(or whatever the string is called.
Examine the output and see if there's anything wrong with the sql statement.
If you don't notice anything wrong, I use a utility method I wrote that executes an SQL statement and prints the results in the immediate window, using CurrentDb.OpenRecordset and iterating over the records and then over each field and printing it out. It may be easier for you to create a query in access and copy/paste the generated SQL statement into SQL view, and see if it gives you an error when switching to Datasheet view.
However before going that far in many cases you can open the properties for the list box while the program is running, after the search has been executed - especially in Access 2007, in layout view. Then go to the row source and click the ... button. If you don't get an error right away see what you get in Datasheet view.
Aug 28 '08 #2
MNNovice
418 256MB
Thanks for your suggestions. I was able to solve my problem.

Hi. I didn't notice anything wrong right away, but I'll tell you how I usually debug these types of problems.
Set a breakpoint in the _Click event after the entire string is composed. The first thing I would do is when the breakpoint is hit, go to the immediate window and print out the contents of the string:
Expand|Select|Wrap|Line Numbers
  1. ? sqlString
(or whatever the string is called.
Examine the output and see if there's anything wrong with the sql statement.
If you don't notice anything wrong, I use a utility method I wrote that executes an SQL statement and prints the results in the immediate window, using CurrentDb.OpenRecordset and iterating over the records and then over each field and printing it out. It may be easier for you to create a query in access and copy/paste the generated SQL statement into SQL view, and see if it gives you an error when switching to Datasheet view.
However before going that far in many cases you can open the properties for the list box while the program is running, after the search has been executed - especially in Access 2007, in layout view. Then go to the row source and click the ... button. If you don't get an error right away see what you get in Datasheet view.
Aug 30 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Andreas Lauffer | last post by:
I changed from Access97 to AccessXP and I have immense performance problems. Details: - Access XP MDB with Jet 4.0 ( no ADP-Project ) - Linked Tables to SQL-Server 2000 over ODBC I used...
8
by: Elliot M. Rodriguez | last post by:
I am having a heckuva time debugging this, or determining why my page is behaving this way. I have a search form, that when completed, returns a datagrid. When the user selects a row (normal...
3
by: Shapper | last post by:
Hello, Until now I have been using Dreamweaver to create ASP.Net/VB web sites. I gave up of using it. Too many limitations. What is the best software to create ASP.NET/VB web sites? Maybe...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
2
by: AA Arens | last post by:
When I push on my find-record button, after I focussed on the ID-number field on my form, the default search field in the Search-form dialog menu is not the focussed field, but another. Why? ...
1
by: atl10spro | last post by:
Hello Everyone, I am new to MS Access and although I have created several different databases I lack the VB knowledge to code a search function. I am turning to your expertise for assistance. ...
3
by: erainc | last post by:
Hi There, I am trying to put a search box on my form in Access 2003. I tried doing it through a combo box, and the search part works, but the rest of the information on the form does not correlate...
9
by: pic078 via AccessMonster.com | last post by:
I need serious help - I have a frontend/backend Access database (2 MDE Files) that remains stuck in task manager after exiting the application - you can't reopen database after exiting as a result...
5
by: ebernedo | last post by:
Hey guys, I'm new here and also pretty new to access I'm creating a database at work, and need to be able to search things within it to find the right part number in our case... heres a sample...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.