Results 1 to 6 of 6
  1. #1
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    434

    findfirst with "like" not matching data

    hi, i have to check if a field (zone) of a record in the recordset contains the value in me.comune, then if not in me.provincia, and finally me.regione
    there is a correspondence but the program do not find it. why?

    Code:
    rs.FindFirst "[Zone] Like '*" & Me.Comune & "*'"         If rs.NoMatch Then
                rs.FindFirst "[Zone] Like '*" & Me.Provincia & "*'"
                If rs.NoMatch Then
                   rs.FindFirst "[Zone] Like '*" & Me.Regione & "*'"
                Else
                   DoCmd.RunSQL ("INSERT INTO EMList ( CandidatoID, Azienda, tipocontatto, Email ) " & vbCrLf & _
                                 "VALUES (""" & rs!IDcandidato & """,""" & rs!Azienda & """, """ & rs!TipoContatto & """, """ & rs![Email ufficio] & """)")
                 
                End If
             Else
                DoCmd.RunSQL ("INSERT INTO EMList ( CandidatoID, Azienda, tipocontatto, Email ) " & vbCrLf & _
                                 "VALUES (""" & rs!IDcandidato & """,""" & rs!Azienda & """, """ & rs!TipoContatto & """, """ & rs![Email ufficio] & """)")
             End If
    [/CODE]

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Dont use findfirst,
    instead just filter all the records then browse them:

    me.filter =“[field] like ‘*” & me.txtBox & “*’”
    me.filterOn=true

  3. #3
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    434
    thanks, actually i have to find in which field "zone" there is the correspondence, then i have to get another field that is the email

    Quote Originally Posted by ranman256 View Post
    Dont use findfirst,
    instead just filter all the records then browse them:

    me.filter =“[field] like ‘*” & me.txtBox & “*’”
    me.filterOn=true
    that's the complete code

    Code:
    Private Sub SegnalazioneBTN_Click()   If Me.CCSceltaTrattativa <> "" Then
          EMCode = "Segnalazione"
          FineMail = "<br><br>Rimango in attesa di un riscontro <br> Buon lavoro"
          DoCmd.SetWarnings False
          Set db = CurrentDb
          Dim MatchVar As Boolean
          MatchVar = False
          Set rs = db.OpenRecordset("SELECT Candidati.IDcandidato, Candidati.[RAL/Fatturato], Candidati.[Patto di non concorrenza], Candidati.[Penale economica], Candidati.[Corrispettivo patto], Candidati.[Ptf banca personale], Candidati.[Ptf trasferibile personale], Candidati.[Redditivitą ptf trasferibile], Candidati.[Numero clienti personali], Candidati.[Data di nascita], DateDiff(""yyyy"",[data di nascita],Date()) AS Etą, Comuni.Comune, Aziende.Azienda, Professioni.PosizioneLavorativa " & vbCrLf & _
                                    "FROM Professioni INNER JOIN (Aziende INNER JOIN (Comuni INNER JOIN Candidati ON Comuni.IDComune = Candidati.ComuneID) ON Aziende.IDazienda = Candidati.AziendaID) ON Professioni.IDposizione = Candidati.PosizioneID " & vbCrLf & _
                                    "WHERE (((Candidati.IDcandidato)= " & Me.IDcandidato & "));")
          rs.MoveFirst
          DoCmd.RunSQL ("UPDATE EMcontent SET EMcontent.Soggetto = """ & rs!PosizioneLavorativa & """ & "" - "" & """ & rs!Azienda & """ & "" - "" & """ & rs!Comune & """ & "" - "" & """ & rs![Ptf trasferibile personale] & """ " & vbCrLf & _
                       "WHERE (((EMcontent.IDOggetto)=""Segnalazione""));")
          DoCmd.RunSQL ("UPDATE EMcontent SET EMcontent.testo = ""di seguito il candidato in oggetto <br> <br> <b> Posizione: </b>"" & """ & rs!PosizioneLavorativa & """ & ""<bR>"" & ""<b> Banca: </b>"" & """ & rs!Azienda & """ & ""<br>"" & ""<b> Sede: </b>"" & """ & rs!Comune & """ & ""<br>"" & ""<b> Etą: </b>"" & """ & rs!Etą & """  & ""<br>"" & ""<b> Portafoglio gestito in banca: </b>"" & """ & rs![Ptf banca personale] & """ & ""<br>"" & ""<b> Portafoglio trasferbile: </b>"" & """ & rs![Ptf trasferibile personale] & """ & ""<br>"" & ""<b> RAL: </b>"" & """ & Format(rs![RAL/Fatturato], "currency") & """ & ""<br>"" & ""<b> Patto: </b>"" & """ & rs![Patto di non concorrenza] & """ & ""<br>"" & ""<b> Penale: </b>"" & """ & Format(rs![Penale economica], "currency") & """ & """ & FineMail & """ " & vbCrLf & _
                       "WHERE (((EMcontent.IDOggetto)=""Segnalazione""));")
                       
          DoCmd.RunSQL ("DELETE * FROM EMlist")
          Set rs = db.OpenRecordset("SELECT Candidati.IDcandidato, Candidati.TipoContatto, candidati.[email ufficio], Aziende.IDazienda, Aziende.azienda,Candidati.nomecognome, Clienti.IDCliente, Candidati.zone " & vbCrLf & _
                                    "FROM Clienti INNER JOIN (Aziende INNER JOIN Candidati ON Aziende.IDazienda = Candidati.AziendaID) ON Clienti.AziendaID = Aziende.IDazienda " & vbCrLf & _
                                    "WHERE (((Candidati.TipoContatto)=""cliente"") AND ((Clienti.IDCliente)= " & Me.TBIDCliente & ") AND ((Candidati.zone)<>""amministrazione""));")
             
          rs.MoveLast
          If rs.RecordCount < 2 Then
             DoCmd.RunSQL ("INSERT INTO EMList ( CandidatoID, Azienda, tipocontatto, Email ) " & vbCrLf & _
                           "VALUES(""" & rs!IDcandidato & """,""" & rs!Azienda & """,""" & rs!TipoContatto & """,""" & rs![Email ufficio] & """)")
          Else
            'cercare in un recordset una parola in un campo, in questo caso contenuta
             rs.FindFirst "[Zone] Like '*" & Me.Comune & "*'"
             If rs.NoMatch Then
                rs.FindFirst "[Zone] Like '*" & Me.Provincia & "*'"
                If rs.NoMatch Then
                   rs.FindFirst "[Zone] Like '*" & Me.Regione & "*'"
                Else
                   DoCmd.RunSQL ("INSERT INTO EMList ( CandidatoID, Azienda, tipocontatto, Email ) " & vbCrLf & _
                                 "VALUES (""" & rs!IDcandidato & """,""" & rs!Azienda & """, """ & rs!TipoContatto & """, """ & rs![Email ufficio] & """)")
                 
                End If
             Else
                DoCmd.RunSQL ("INSERT INTO EMList ( CandidatoID, Azienda, tipocontatto, Email ) " & vbCrLf & _
                                 "VALUES (""" & rs!IDcandidato & """,""" & rs!Azienda & """, """ & rs!TipoContatto & """, """ & rs![Email ufficio] & """)")
             End If
              
          rs.Close
          Set rs = Nothing
          End If
          DoCmd.OpenForm "mailer", acNormal, , , acFormEdit, acWindowNormal, EMCode
          DoCmd.SetWarnings True
       End If
    End Sub

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,558
    Works for me, in a text or memo field, so not sure why not with you.?

    Code:
    rs.FindFirst "[Zone] Like '*" & Me.Comune & "*'"
    If rs.NoMatch Then
        rs.FindFirst "[Zone] Like '*" & Me.Provincia & "*'"
        If rs.NoMatch Then
            rs.FindFirst "[Zone] Like '*" & Me.Regione & "*'"
        Else
            DoCmd.RunSQL ("INSERT INTO EMList ( CandidatoID, Azienda, tipocontatto, Email ) " & vbCrLf & _
                          "VALUES (""" & rs!IDcandidato & """,""" & rs!Azienda & """, """ & rs!TipoContatto & """, """ & rs![Email ufficio] & """)")
    
        End If
    Else
        DoCmd.RunSQL ("INSERT INTO EMList ( CandidatoID, Azienda, tipocontatto, Email ) " & vbCrLf & _
                      "VALUES (""" & rs!IDcandidato & """,""" & rs!Azienda & """, """ & rs!TipoContatto & """, """ & rs![Email ufficio] & """)")
    End If
    Have you even stepped through your code?
    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
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    434
    it's a long text field (ust changed from short text), the table is stored in sharepoint, but i dont think this is the problem.
    i stepped into my code, but i cannot find useful infos...

    Quote Originally Posted by Welshgasman View Post
    Works for me, in a text or memo field, so not sure why not with you.?

    Code:
    rs.FindFirst "[Zone] Like '*" & Me.Comune & "*'"
    If rs.NoMatch Then
        rs.FindFirst "[Zone] Like '*" & Me.Provincia & "*'"
        If rs.NoMatch Then
            rs.FindFirst "[Zone] Like '*" & Me.Regione & "*'"
        Else
            DoCmd.RunSQL ("INSERT INTO EMList ( CandidatoID, Azienda, tipocontatto, Email ) " & vbCrLf & _
                          "VALUES (""" & rs!IDcandidato & """,""" & rs!Azienda & """, """ & rs!TipoContatto & """, """ & rs![Email ufficio] & """)")
    
        End If
    Else
        DoCmd.RunSQL ("INSERT INTO EMList ( CandidatoID, Azienda, tipocontatto, Email ) " & vbCrLf & _
                      "VALUES (""" & rs!IDcandidato & """,""" & rs!Azienda & """, """ & rs!TipoContatto & """, """ & rs![Email ufficio] & """)")
    End If
    Have you even stepped through your code?

  6. #6
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    434
    don't mind, i just thoght that i have to rebuild the whole structure for other reasons...thanks

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

Similar Threads

  1. Replies: 8
    Last Post: 04-21-2021, 09:44 AM
  2. Replies: 28
    Last Post: 03-23-2021, 11:02 AM
  3. Replies: 1
    Last Post: 09-07-2015, 08:00 AM
  4. Replies: 5
    Last Post: 05-28-2015, 03:27 PM
  5. Replies: 5
    Last Post: 10-18-2013, 05:03 PM

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