-
Jul 7th, 2012, 03:37 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Code!!!
Dear Programer, Need your expert. I did do search based on [Customer_Name] and it's work fine.
Code:
If pt.State = adStateOpen Then pt.Close
pt.Open "SELECT * FROM [Customer] WHERE [Customer_Name] LIKE '%" & Trim(txtFind) & "%'", db, adOpenStatic, adLockOptimistic
- But when I want to expand my Search to be based on 2 things [Customer_Name] or [Customer_No], Code below crushed not working. Any help would be such appreciate:
Code:
If pt.State = adStateOpen Then pt.Close
pt.Open "SELECT * FROM [Customer] WHERE [Customer_Name] LIKE '%" & Trim(txtFind) & "%' OR [Customer_No] LIKE '%" & Trim(txtFind) & "%'", db, adOpenStatic, adLockOptimistic
Last edited by brss; Jul 9th, 2012 at 06:04 AM.
-
Jul 7th, 2012, 09:13 PM
#2
Re: Code!!!
u used the same txt field for both cust name and no.
-
Jul 7th, 2012, 09:18 PM
#3
Re: Code!!!
Code:
[Customer_Name] LIKE '%" & Trim(txtFind) & "%' and [Customer_No] LIKE '%" & Trim(txtFind)
If your intent is to match both then you probably need to change txtfind to something else in one of them
If your intent is to search both fields and match either of them then you should be using OR instead of AND
also if customer_no is a numeric field as the name would imply then you should not be encasing it in 's
-
Jul 7th, 2012, 09:44 PM
#4
Member
Re: Code!!!
Does LIKE work with numeric fields? If I recall, LIKE is for matching text fields.
Regards, SGarv
-
Jul 7th, 2012, 11:47 PM
#5
Re: Code!!!
Not sure, I've never had a reason to try it on a numeric field. I would be surprised if it did though.
-
Jul 7th, 2012, 11:59 PM
#6
Thread Starter
Hyperactive Member
Re: Code!!!
Dear DataMiser, Code above work fine with Names. I don't want to Create much fields for Search. I just want from one Text fields do search on Name or Numbers or date as I described above. Any suggest would be appreciated. Thank you a lot for your precious time spending here.
-
Jul 9th, 2012, 06:02 AM
#7
Thread Starter
Hyperactive Member
Re: Code!!!
I did try to search number or search date so i coded as described below it's not work. My question, Can we from text field search name and number using like as code shows in post #1? And sorry to bother your all with my questions. Thank you vbforum. Best site ever saw.
Code:
If pt.State = adStateOpen Then pt.Close
pt.Open "SELECT * FROM [Customer] WHERE [Customer_No] LIKE '#" & Trim(txtFind) & "#'", db, adOpenStatic, adLockOptimistic
-
Jul 13th, 2012, 11:18 AM
#8
Thread Starter
Hyperactive Member
Re: Code!!!
I found way to do search based on String and Date using like. Thank you All
Code:
Private Sub cmdFind_Click()
'
If pt.State = adStateOpen Then pt.Close
pt.Open "SELECT * FROM [Customer] WHERE [Customer_No] LIKE '" & Trim(txtFind) & "%' OR [Customer_Name] LIKE '%" & Trim(txtFind) & "%'", db, adOpenStatic, adLockOptimistic
Call MSHFlexgridAlignment
End Sub
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
|