sorry for double posting.. but yes.. i need a query to search all of the 40 fields cause atm i open a query and manually have to type the word I am searchign for into 40 lins of the query
This is very messy and a bit naff but I don't know what else you can do with a table like this.
Also I am doing this blind so it may have a fair few syntax errors.
Make a form with:
1 textbox call it txtCriteria
1 button: call it cmdSearch
Then right click the button and click on build event and then click on code builder.
The VBA window appears and you should see
Code:
Private Sub cmdSearch_Click()
End Sub
Inside this Sub you need to write the code that creates and runs your query.
Code:
Private Sub cmdSearch_Click()
Dim sSearchMusic As String
Dim sCriteria as string
sCriteria = txtCriteria
sSearchMusic = "SELECT * FROM YourTable"
On Error Resume Next
Call CurrentDb.QueryDefs.Delete("qryMusicSearch")
Call CurrentDb.CreateQueryDef("qryMusicSearch", sSearchMusic)
DoCmd.OpenQuery "qryMusicSearch"
End Sub
This code should create and run your query. However the query that it runs in the above example isn't the one you want.
You need to open the query that you have already made, right click on the title bar of the query window and select SQL View.
This will show you the SQL command that you need to copy and paste in the above code.
Code:
sSearchMusic = "Your query here"
The only difference is that in the SQL string you have copied there will be a load of text after the WHERE clause and it will say almost the same thing over and over again. This wont be exact but you get the idea
Code:
WHERE .... Singer1 Is Like *yoursearchtext* OR Singer2 Is Like *yoursearchtext* OR Singer3 Is Like *yoursearchtext* .... etc etc.
you need to go through all this text and remove yoursearchtext and replace it with " & sCriteria & "
Code:
WHERE .... Singer1 Is Like *" & sCriteria & "* OR Singer2 Is Like *" & sCriteria & "* OR Singer3 Is Like *" & sCriteria & "* .... etc etc.
When you have changed the text then it should work. You click the button and the query opens.