@ssanfu
ehehe, too many posts!!!
First, thank you! Ok for the apostrophes, new thing learned. Infact I have some, but I solved the problem using a similar symbol, so that Access doesn't recognize it as the "official" apostrophe.
The db now is ok (I will have a look at the one you have uploaded, to compare it with the final version of the one made till now).
The last "problem" (that is not a problem :P ) is: now I can export PDF as I needed, and I'd like to edit that code (on another button) not to make an output but only to search, just to see pages (all together is ok) before exporting them. I removed the lines about "exporting" from the code, but I can visualize only 1 page, and not all the pages that come from sCriteria.
The code is the following:
Code:
Dim MyDB As DAO.Database
Dim MyRS As DAO.Recordset
Dim strSQL As String
Dim strRptName As String
Dim sCriteria As String
Dim strWhere As String
Dim lngLen As Long
Set MyDB = CurrentDb
strRptName = "Attestati_2014"
If Not IsNull(Me.qcognome1) Then
strWhere = strWhere & "(Cognome Like ""*" & Me.qcognome1 & "*"") AND "
End If
If Not IsNull(Me.qncorso1) Then
strWhere = strWhere & "(N_corso = " & Me.qncorso1 & ") AND "
End If
If Not IsNull(Me.qnmodulo1) Then
strWhere = strWhere & "(N_modulo = " & Me.qnmodulo1 & ") AND "
End If
lngLen = Len(strWhere) - 5
If lngLen > 0 Then
strWhere = "WHERE " & Left$(strWhere, lngLen)
End If
strSQL = "Select Selezione_corso_2014.[Cognome], Selezione_corso_2014.[Data_modulo],Selezione_corso_2014.[Nome] From Selezione_corso_2014 " & strWhere & ";"
Set MyRS = MyDB.OpenRecordset(strSQL, dbOpenForwardOnly)
With MyRS
sCriteria = "[Cognome]='" & ![Cognome] & "' and [N_corso]='" & ![N_corso] & " and [N_modulo] = " & ![N_modulo] & ""
DoCmd.OpenReport strRptName, acViewPreview, , sCriteria
End With
MyRS.Close
Set MyRS = Nothing
MsgBox "Done"
and the error is: 3075, too many parenthesys in (Cognome = ) AND (N_corso = 1) AND (N_modulo = )
@June7
Well.. I can't understand that thought: I only asked for a help because it's not my job and I only needed a help in costructing something that is not familiar to me!
If I wanted to learn or if I knew VBA, I would have done by myself. I'm not a person that ask because doesn't want to do..
I come from another field of work, and I only asked.. I can't learn now how to build VBA in 1 week! I will do it in my sparetime! If it is too complicated to explain, give up! I'm not forcing anyone.. but please, don't ask me to read a course or a long explanation of VBA now.. I can't understand..
I prefer learning by doing, and it's what I'm doing.. and I learned so much, starting from what you had written and from ssanfu first example-DB.
I can't provide the DB.. it contains private data of people. I can't!!