Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    434

    Extract the right field from recordsource

    hi, i have this recordsource (cutted of the part after FROM)



    Code:
    SELECT Trattative.IDtrattativa, Trattative.CandidatoID, Aziende_1.Azienda AS [Banca candidato], Candidati.nomecognome, Comuni.Comune, Aziende.Azienda, Trattative.StatoTrattativa, Trattative.Fase, Trattative.Manager, Trattative.Nostra, Trattative.[Data inizio trattativa], Trattative.[Data fine trattativa], Trattative.[Head hunter], Trattative.[Ral nuova], Trattative.NumeroCandidatoCliente, Trattative.Note, Candidati.[ptf trasferibile personale]
    i have a combobox that has as source the field list of this query; as you can say i have two similar fields, "[Banca candidato] that is Aziende_1.Aziende" and Aziende.Azienda.

    since i use this combo to filter the query, how can i get the correct name field from combobox?

    If i choose [banca candidato] i can't use this value to filter, cause the real name is "Aziende_1.azienda", if i choose "azienda" i'm not able to find the correct name that is "aziende.azienda" and not "aziende_1.Azienda"

    thanks

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    you can rename the field in the query to stop duplicate confusion:

    ..Comuni.Comune, Az1: Aziende.Azienda, ...

    then use
    Az1 on the form

  3. #3
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    434
    Quote Originally Posted by ranman256 View Post
    you can rename the field in the query to stop duplicate confusion:

    ..Comuni.Comune, Az1: Aziende.Azienda, ...

    then use
    Az1 on the form

    and then extract the string after the ":"..right

    or better, extract the part before the "as"

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,938
    You reference a combo by its name and column number

    My combo.column(1)

    References the second column

  5. #5
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    IIRC, you cannot use .Column(x) in a query?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,938
    Agreed - thought op was building a filter in vba

  7. #7
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    You are probably correct, as usual. I try to go first by the post title then the forum area. So much gets posted in "Access" that it's hard to tell. At first I had recordset in mind, figuring if a field was in your recordsource what's there to extract? Then I thought this was about an alias for a field because of
    "the real name is "Aziende_1.azienda", if i choose "azienda" i'm not able to find the correct name"

    I thought you were suggesting using Column(x) in the posted sql.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    434
    sorry, i got a bit confused.

    i tried when in after update event of the combobox to get the value through a msgbox, i used "msgbox(me.mycombo.column(1))", changing the column number to 0 to 3, but for "[banca candidato]" field which the real value is Aziende_1.Azienda, i get only the name [banca candidato], not Aziende_1.Azienda

  9. #9
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,938
    Really struggling to understand what you are trying to achieve. You wrote the rowsource, you know what each column means, why does it matter if a column has been aliased?

  10. #10
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,938
    Implication is your field list is based on a query based on multiple tables.

    So what are you trying to filter? A form recordsource based on this query? Something else?

  11. #11
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    434
    Well, i made a form to filter forms, both based on table (easy) and query.

    in this case, i'm trying to filter this recordsource

    Code:
    SELECT Trattative.IDtrattativa, Trattative.CandidatoID, Aziende_1.Azienda AS [Banca candidato], Candidati.nomecognome, Comuni.Comune, Aziende.Azienda, Trattative.StatoTrattativa, Trattative.Fase, Trattative.Manager, Trattative.Nostra, Trattative.[Data inizio trattativa], Trattative.[Data fine trattativa], Trattative.[Head hunter], Trattative.[Ral nuova], Trattative.NumeroCandidatoCliente, Trattative.Note, Candidati.[ptf trasferibile personale] FROM Comuni RIGHT JOIN (Aziende AS Aziende_1 RIGHT JOIN ((Clienti RIGHT JOIN (Candidati INNER JOIN Trattative ON Candidati.IDcandidato = Trattative.CandidatoID) ON Clienti.IDCliente = Trattative.ClienteID) LEFT JOIN Aziende ON Clienti.AziendaID = Aziende.IDazienda) ON Aziende_1.IDazienda = Candidati.AziendaID) ON Comuni.IDComune = Candidati.ComuneID;
    i create a sql string to filter the recordsource above, but when i got those duplicates (aziende.azienda and aziende_1.azienda) i'm not able to extract correctly the name of the field

    i cannot use the text of the combobox that has fields as rowsource, cause it is not "Aziende.azienda" but i get just "azienda", and sql string do not work

  12. #12
    Join Date
    Apr 2017
    Posts
    1,792
    Maybe you have to set form's Filter property (or add WHERE clause to your query) as
    Code:
    Aziende_1.Azienda = FilterValueForBancaCandidato AND Azienda.Azienda = FilterValueForAzienda
    Depending on on your data and what you want to achive, both filter values may be same, or they may differ.

  13. #13
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,938
    So much missing from what you are telling us. If the combo is supposed to be listing the fields in the recordsource the user can select from to filter why would they be different? You would use the same sql

    If you are applying a filter, you would apply it to the aliased name so I still don’t see what the issue is.

    Suggest you step back, explain how your forms/combo are intended to work

  14. #14
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    434
    EDIT I remebered:

    the problem is that i have three combobox

    Combo 1: in which i select the name of the field that i want to use to filter
    Combo 2: in which i have the operator (=,<>, startwith etc etc)
    Combo 3: the value that the recordsource has to matche

    e.g.
    combo 1: Name
    Combo 2: =
    Combo 3: "Mickey mouse"


    the real problem is that when i use the "=" or "<>" operator i want to limit the rowsource of the combobox 3 to the values present in the recordsource
    i use this code

    Code:
      If Me.combo1= "multivalue" Then            Set ValuesRs = db.OpenRecordset("SELECT DISTINCT " & FldVar & ".value" & " " & FldOrigin)
                Set Me.Value1CB.Recordset = ValuesRs
             Else
               Set ValuesRs = db.OpenRecordset("SELECT DISTINCT " & FldVar & " " & FldOrigin & " WHERE " & FldVar & " is not null")
               Set Me.Value1CB.Recordset = ValuesRs
                'MsgBox ("SELECT DISTINCT " & FldVar & " " & FldOrigin & " WHERE " & FldVar & " is not null")
             End If
    fldvar is the name of the field in combo1
    fldorigin is the recordsource cutted from the "FROM" of the sql

    as you can see, i cannot use the aliased name.
    what should i do? filter the rowsource of combo 3 in another way?

  15. #15
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,938
    seen to have moved the goalposts - your sql build does not include a FROM

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Extract text from a field
    By murleyj in forum Queries
    Replies: 7
    Last Post: 04-02-2015, 02:53 PM
  2. Update recordsource of one field on a form
    By TinaCa in forum Programming
    Replies: 1
    Last Post: 03-06-2012, 06:56 PM
  3. extract something from a field
    By tozey in forum Queries
    Replies: 4
    Last Post: 02-24-2012, 08:54 AM
  4. Extract certain values from field
    By tylerg11 in forum Programming
    Replies: 19
    Last Post: 09-23-2011, 03:27 PM
  5. Set Label.Caption to field of recordsource
    By ngruson in forum Forms
    Replies: 1
    Last Post: 08-11-2010, 09:59 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