Originally Posted by
June7
It's possible, a little complicated but certainly possible.
"SELECT * FROM sqlbookmark WHERE LecturuerID=" & Me.Lecturer & " AND Data_contratto=#" & DMax("Data_contratto", "sqlbookmark", "LecturerID=" & Me.Lecturer) & "#"
But exactly how is the subform filtered to provide the correct records? Instead of building the same SQL in VBA, maybe use the subform's recordset. The syntax depends on location of code. If it is behind main form: Set Recordset = Me.subformname.Form.Recordset
But I am confused. Why are the Word bookmarks set to values from subform instead of recordset? If code is behind main form then these references to subform fields/controls should fail.
And regarding variable Tbl - I have never seen a variable declared that way.
Micron is advising not to use the word 'Recordset' as a variable name because it is a reserved word. This variable has not been declared in the posted code. Every code module should have 'Option Explicit' in the module header.
https://docs.microsoft.com/en-us/dot...icit-statement
Hi.
Your code again perfectly solved the problem. You're great, thank you!
I try to answer your questions, and sorry if I am not too precise, I am a beginner...
Main form and subform are based on two different tables, with other two used as lookup:
Part of the word bookmarks are populated from fields taken from the main form (anagraphical), and part from the fields from the subform. The reference for populating from the subform is a query, that I named "sqlbookmark", collecting all the fields I need to populate the word, ordered by contract date (Data_contratto) and protocol number (prot). Here's the query SQL:
Code:
SELECT Anagrafica_docenti.ID_Anagrafica_docenti, Anagrafica_docenti.NOME, Anagrafica_docenti.COGNOME, Anagrafica_docenti.INDIRIZZO, Anagrafica_docenti.[CODICE FISCALE], Anagrafica_docenti.PIVA, Anagrafica_art_corsi.UD, Anagrafica_materie.Nome_materia, Anagrafica_corsi.Nome_corso, Anagrafica_art_corsi.EDIZIONE, Anagrafica_art_corsi.MODULO, Anagrafica_art_corsi.ANNUALITA, Anagrafica_art_corsi.ANNO, Anagrafica_art_corsi.DATA_CONTRATTO, Anagrafica_art_corsi.PROTOCOLLO, Anagrafica_art_corsi.TITOLO_CORSO, Anagrafica_art_corsi.COMM, Anagrafica_art_corsi.NUMERO_ORE, Anagrafica_art_corsi.DAL, Anagrafica_art_corsi.AL, Anagrafica_art_corsi.COSTO_ORARIO
FROM Anagrafica_materie INNER JOIN (Anagrafica_corsi INNER JOIN (Anagrafica_docenti INNER JOIN Anagrafica_art_corsi ON Anagrafica_docenti.ID_Anagrafica_docenti = Anagrafica_art_corsi.ID_Anagrafica_docenti) ON Anagrafica_corsi.ID_Anagrafica_corsi = Anagrafica_art_corsi.CORSO) ON Anagrafica_materie.ID_anagmaterie = Anagrafica_art_corsi.MATERIA
ORDER BY Anagrafica_art_corsi.DATA_CONTRATTO DESC , Anagrafica_art_corsi.PROTOCOLLO DESC;
As you may see, the recordset is already built from the subform's SQL.
The code is actually behind a button put in the mainform: top-right, called "Estrai occasionale".
As for the variable "Tbl" it is just junk remained from the cleaning up of the original code... sorry.
Actually I didn't got the meaing about the reserved word "recordset". I will try go through the link you gave me (thank you!).
But before I have to solve a strange problem: after extraction and word populating, the database goes mad... some fields disappear and show a #Nome?, and the database can't be browsed anymore if not closing and re-open it...