Results 1 to 8 of 8

Thread: [RESOLVED] Code!!!

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2012
    Location
    I'm living in VBForum bcz its members deserve respect and appreciation
    Posts
    333

    Resolved [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.

  2. #2
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: Code!!!

    u used the same txt field for both cust name and no.
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  3. #3
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    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

  4. #4
    Member sgarv's Avatar
    Join Date
    Jul 2012
    Posts
    34

    Re: Code!!!

    Does LIKE work with numeric fields? If I recall, LIKE is for matching text fields.

    Regards, SGarv

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    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.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2012
    Location
    I'm living in VBForum bcz its members deserve respect and appreciation
    Posts
    333

    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.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2012
    Location
    I'm living in VBForum bcz its members deserve respect and appreciation
    Posts
    333

    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

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2012
    Location
    I'm living in VBForum bcz its members deserve respect and appreciation
    Posts
    333

    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
  •  



Click Here to Expand Forum to Full Width