See example code in post 41.
And need to include Data_modulo in the report filter criteria parameter along with Cognome.
See example code in post 41.
And need to include Data_modulo in the report filter criteria parameter along with Cognome.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
oops, this thread is so long I forgot what the first post was....
Don't worry!! ahaha
ok, I've changed that line and added that parameter.. not the error is still 3061 but needed parameters are 4 :P
what do I have to put into [some field name] and controlname? which one?
You need to learn how to construct strings by concatenating literal text with variables.
You have done some with:
DoCmd.OpenReport strRptName, acViewPreview, , "[Cognome]='" & ![Cognome] & "'"
Now expand on that:
DoCmd.OpenReport strRptName, acViewPreview, , "[Cognome]='" & ![Cognome] & "' AND [Data_modulo]=#" & !Data_modulo & "#"
And also apply filter to the recordset SQL instead of using dynamic parameters in query object.
Did you remove dynamic parameters from the query object?
Example for text, date, number field:
strSQL = "Select Selezione_corso_2014.[Cognome], Selezione_corso_2014.[Data_modulo] From Selezione_corso_2014 WHERE [a text field name]='" & Me.textinputcontrol & "' AND [a date field name]=#" & Me.dateinputcontrol & "# AND [a number field name]=" & Me.numberinputcontrol & ";"
Construct as appropriate for your filter requirements and use the names of your fields and controls.
If you are using international data structure, that will cause another set of issues when filtering with date values. Review: http://allenbrowne.com/ser-36.html
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
@ingarchsf,
I must say that you have helped me by making me work on the code to export reports in PDF.
Maybe an example will help you. So attached is the dB I created to test the export to PDF.
It is very basic.....
I've tried, but it says that there is an error in [datefieldname]..You need to learn how to construct strings by concatenating literal text with variables.
You have done some with:
DoCmd.OpenReport strRptName, acViewPreview, , "[Cognome]='" & ![Cognome] & "'"
Now expand on that:
DoCmd.OpenReport strRptName, acViewPreview, , "[Cognome]='" & ![Cognome] & "' AND [Data_modulo]=#" & !Data_modulo & "#"
And also apply filter to the recordset SQL instead of using dynamic parameters in query object.
Did you remove dynamic parameters from the query object?
Example for text, date, number field:
strSQL = "Select Selezione_corso_2014.[Cognome], Selezione_corso_2014.[Data_modulo] From Selezione_corso_2014 WHERE [a text field name]='" & Me.textinputcontrol & "' AND [a date field name]=#" & Me.dateinputcontrol & "# AND [a number field name]=" & Me.numberinputcontrol & ";"
Construct as appropriate for your filter requirements and use the names of your fields and controls.
If you are using international data structure, that will cause another set of issues when filtering with date values. Review: http://allenbrowne.com/ser-36.html
I have helped? ahah.. honored!!
I've tried your DB, and it's exactly what I'm looking for!!
I've also tried to put the code inside my DB.. but there's somehing that I don't understand: I've seen that in some cases, the date has month and day inverted!! Or.. some PDF has no data.. even if they exist as "date".
There is another thing that I need to use: in the Form you have used only a text box, and I need to use also 2 number box (N_corso and N_modulo) which have 2 parameters (qncorso1 and qnmodulo1), which are used to select records inside Selezione_corso_2014.
I0ve tried to add a "WHERE" condition, using what June7 has posted, but I'm not able -.-°
Last edited by ingarchsf; 08-29-2014 at 02:44 PM. Reason: partially solved
What is error message? Instead of [datefieldname] use your actual field name.
Did you review Allen's link about international date?
Post your attempted code or provide your database.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Ok, now dates are ok.. but some PDF has no data.. even if they exist as "date".
UPDATE: no.. some dates are ok, some other are inverted O_O..
Don't know what that means. Not something I can analyse.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
about dates: I've tried to write into "Format" option (in the table) the format gg/mm/aaaa, the same into the option "Format" of the query that takes from the table.. but the result is the same..
some dates are ok, i.e. 20/05/2014 (20th may 2014), but others are not, i.e. 06/05/2014 (6th may 2014) which is turned to 05/06/2014 (5th june 2014)..
example1: in the table, both exist, but.. the PDFdocument that belongs to 06/05/2014 is written 20140605 and the PDFdocument that belongs to 05/06/2014 is written 20140506.. exactly the opposite!!
example2: in the table, only 03/06/2014 (3rd june 2014) exists.. the PDFdocument 20140603 referred to that date is BLANK.. with type error inside..
UPDATE: the only solution that I've found is changing settings in Windows -.-° another solution? :P
Setting the format property in table or textbox does not alter the actual value used by search and filter. Must use Format function which results in a string value.
I do not fully understand how to deal with international dates because not a concern for me. I do know that if you want to have users input values as dd/mm/yyyy structure, life will be very frustrating.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
@June7: ok, so, that is not a problem, editing Windows settings..
@ssanfu: The other thing to add is: in the Form I need to use also 2 number boxes (N_corso and N_modulo) which have 2 parameters (qncorso1 and qnmodulo1), which are used to select records inside Selezione_corso_2014.
I've tried to add a "WHERE" condition, but I'm not able -.-°
This is the base code, edited for my db, and it works. I need to add other 2 parameters to make the selection (at least one) besides "cognome" [N_corso and N_modulo are numeric fields]
Code:Private Sub ExportPDF_Click() Dim MyDB As DAO.Database Dim MyRS As DAO.Recordset Dim strSQL As String Dim strRptName As String Dim sCriteria As String Set MyDB = CurrentDb strRptName = "Attestati_2014" strSQL = "Select Selezione_corso_2014.[Cognome], Selezione_corso_2014.[Data_modulo] From Selezione_corso_2014 " strSQL = strSQL & " WHERE Cognome ='" & Me.qcognome1 & "'" & " WHERE N_corso =" & Me.qncorso1 & "" & " WHERE N_modulo =" & Me.qnmodulo1 &"" Set MyRS = MyDB.OpenRecordset(strSQL, dbOpenForwardOnly) With MyRS Do While Not MyRS.EOF sCriteria = "[Cognome]='" & ![Cognome] & "' and [Data_modulo] = #" & ![Data_modulo] & "#" DoCmd.OpenReport strRptName, acViewPreview, , sCriteria DoCmd.OutputTo acOutputReport, strRptName, acFormatPDF, "C:\Attestati\" & ![Cognome] & "_" & Format(![Data_modulo], "YYYYMMDD") & ".pdf", False DoCmd.Close acReport, strRptName .MoveNext Loop End With MyRS.Close Set MyRS = Nothing MsgBox "Done" End Sub
Don't repeat the WHERE key word. It is used only once in an SQL statement.
" WHERE Cognome ='" & Me.qcognome1 & "' AND N_corso =" & Me.qncorso1 & " AND N_modulo =" & Me.qnmodulo1
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
it doesn't work however.. syntax error
Code:strSQL = strSQL & " WHERE Cognome ='" & Me.qcognome1 & "' AND N_corso =" & Me.qncorso1 & " AND N_modulo =" & Me.qnmodulo1 "