Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2021
    Posts
    14

    Question find part of the field

    Hello, my name is Giulio and i'm newbie with Access.
    I'm trying to make this function, but i would like find part of the field "consulente/specialista"
    Any tip?


    Function SearchCriteria20()


    Dim ConsulenteCstr As String
    Dim Task, strCriteria As String


    If IsNull(Me.CasellaCombinata64) Then

    ConsulenteCstr = "[consulente/specialista] LIKE '*" & CasellaCombinata64.Value & "*'"

    Else


    ConsulenteCstr = "[consulente/specialista] = '" & Replace(Me.CasellaCombinata64, "'", "''") & "'"


    End If


    strCriteria = ConsulenteCstr
    Task = "Select * from [Query Pratiche Studio Totale 2] where " & strCriteria
    Me.ComboBoxCustomerSearch.Form.RecordSource = Task


    Me.ComboBoxCustomerSearch.Form.Requery
    End Function

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    So what problems are you having Guilio?

    Firstly Task is a variant not a string.? In VBA you must define each variable eg Dim Task As String, strCriteria As String etc
    If the combo is Null, I do not see the need for any criteria?
    So I would test if ConsulenteCstr length is > than zero, and if so add the WHERE and the strCriteria.?
    I would have also thought that you would need the Like and * as you have when Null, if you want to find it anywhere in the field?
    No need for a Requery if you change the recordsource as well.

    HTH
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Join Date
    Mar 2021
    Posts
    14
    It works well atm.
    My question is:
    Title = Giulio, Stefano, Marco, Enrico, Edoardo, etc
    Why when i look for "ar" i dont find any record? i want find Marco and Edoardo for example. TitleCstr = "[Title] like '*'" is it correct? Where am i wrong?

    Private Sub CasellaCombinata51_AfterUpdate()


    Dim TitleCstr As String
    Dim Task As String


    If IsNull(Me.CasellaCombinata51) Then
    TitleCstr = "[Title] like '*'"
    Else
    TitleCstr = "[Title] = '" & Replace(Me.CasellaCombinata51, "'", "''") & "'"

    End If


    Task = "Select * from [Query Pratiche Studio Totale 2] where " & TitleCstr
    Me.ComboBoxCustomerSearch.Form.RecordSource = Task
    End Sub

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Like I said, you need to use the Like (just as you do when there is no need for a criteria?)
    With your code you are saying you want a record which is EQUAL to the combo?

    Add a Debug.Print TitleCstr to see the criteria TitleCstr
    Last edited by Welshgasman; 03-10-2021 at 12:09 PM.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    CarlettoFed is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Dec 2019
    Posts
    255
    Private Sub CasellaCombinata51_AfterUpdate()
    Dim TitleCstr As String
    Dim Task As String
    If isnull(Me.CasellaCombinata51) Then
    TitleCstr = ""
    Else
    TitleCstr = " WHERE [Title] Like ""*" & Me.CasellaCombinata51 & "*"""
    End If
    Task = "Select * From [Query Pratiche Studio Totale 2]" & TitleCstr
    Me.ComboBoxCustomerSearch.Form.RecordSource = Task
    End Sub

  6. #6
    Join Date
    Mar 2021
    Posts
    14
    Thank you guys!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 08-27-2020, 06:50 AM
  2. Replies: 3
    Last Post: 07-23-2019, 10:27 AM
  3. Replies: 1
    Last Post: 05-27-2015, 08:57 AM
  4. Part of field matches part of another field
    By fishhead in forum Queries
    Replies: 13
    Last Post: 04-10-2015, 01:54 PM
  5. Find command default make it Any part of field
    By techexpressinc in forum Forms
    Replies: 0
    Last Post: 03-15-2011, 07:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums