|
-
Jun 21st, 2000, 08:09 AM
#1
Thread Starter
Junior Member
I have two strings that I would like to incorporate into a search function.
Dim StringText As String
Dim StringCombo As String
StringText = Form1.SearchString
StringCombo = Form1.ComboSelect
*******Gold.RecordSource = "select * from Gold " & _
"where " & StringCombo & " = '" & StringText & "'"***********
Gold.Refresh
Form1.Hide
That is what I have as my search Button Function. Now where the astrerisk are is where i am having a problem. I want to be able to search in my database called Gold in the Table and in the Category that is listed in my ComboSelect Box. I am looking for what is in the StringText Variable. If that makes sense at all. I hope it does. I want to make this search feature available for all my categories not just one section of it.
-
Jun 21st, 2000, 10:44 AM
#2
Lively Member
I think your only problem is the syntax you are using in the Sql statement. Give this a try:
Dim fieldStr As String
Dim searchStr as string
set searchStr = Form1.SearchString
set fieldStr = Form1.ComboSelect.text
Gold.recordsource = "SELECT * FROM [GOLD] WHERE " & _
"[" & fieldStr & "] = '" & searchStr & _
"'"
gold.refresh
This is assuming that you are using a field that contains text, and not numeric or date fields. If you are using the other types of fields you would have to change the quotes to the correct syntax. Nothing for numeric fields and # for date fields.
Hope This Helps.
-
Jun 21st, 2000, 11:05 PM
#3
Thread Starter
Junior Member
Thanks Jimmer for your help. I think I got the SQL statement now fixed. When I run the program and try to use the search feature, it gives me a "Compile Error Object Required". And It points to
Set searchStr = Form1.SearchString
I don't know what exactly is wrong with it. Can anyone help?
Thanks a Bunch.
-
Jun 21st, 2000, 11:24 PM
#4
New Member
Do you have database set?
Something like Set db = CurrentDB
-
Jun 21st, 2000, 11:31 PM
#5
Guru
do not use Set when working with non-object variables. SET should only be used when assigning objects. remove the SET from your statements and you should be fine:
searchStr = Form1.SearchString
fieldStr = Form1.ComboSelect.text
-
Jun 21st, 2000, 11:56 PM
#6
Thread Starter
Junior Member
Well I followed the suggestions and now I still got the problem back in the SQL statement. I am getting a Run-time error with Object Required.
This is what I have for the code as we speak.
Private Sub SearchButton_Click()
Dim fieldStr As String
Dim searchStr As String
searchStr = Form1.SearchString
fieldStr = Form1.ComboSelect.Text
Gold.RecordSource = "SELECT * FROM [GOLD] WHERE " & _
"[" & fieldStr & "] = '" & searchStr & _
"'"
Gold.Refresh
Form1.Hide
End Sub
Thanks,
-
Jun 22nd, 2000, 02:12 AM
#7
Frenzied Member
It sounds like there's an object missing on your form
I'd replace the code you have:
Dim fieldStr As String
Dim searchStr As String
searchStr = Form1.SearchString
fieldStr = Form1.ComboSelect.Text
Gold.RecordSource = "SELECT * FROM [GOLD] WHERE " & _
"[" & fieldStr & "] = '" & searchStr & _
"'"
with
Gold.RecordSource = "SELECT * FROM [GOLD] WHERE " & _
"[" & trim(Form1.ComboSelect.Text) & "] = '" & trim(Form1.SearchString) & _
"'"
-
Jun 22nd, 2000, 02:36 AM
#8
Thread Starter
Junior Member
Man this is starting to suck. I am still getting the Run Time Error "424" Object required.
Any more ideas?
Joseph
-
Jun 22nd, 2000, 02:42 AM
#9
Frenzied Member
It sounds like the form objects don't exist (or maybe you have a typo)...
-
Jun 22nd, 2000, 03:02 AM
#10
Thread Starter
Junior Member
The only thing I can think of is that I did the combo box wrong. Can someone tell me how to make entries into the combo box and I can see if I did it right?
Joe
-
Jun 22nd, 2000, 07:39 AM
#11
Thread Starter
Junior Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|