Page 6 of 7 FirstFirst 1234567 LastLast
Results 76 to 90 of 100
  1. #76
    ingarchsf is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    50
    N_modulo is a number field (1, 2, 3, ...) and Data_modulo is a date field (01/09/2014).



    N_modulo is used only for selection, Data_modulo is used for the name of the PDF.

    The problem is in If instruction: seems that doesn't recognize qncorso1 and qnmodulo1..

  2. #77
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Maybe because in the code there is letter "l" at the end instead of number "1".

    qncorsol
    qncorso1

    qnmodulol
    qnmodulo1

    Have you run Debug > Compile?
    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.

  3. #78
    ingarchsf is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    50
    *_* wow.. a stupid mistake! I don't know why..

    byw.. ok, I've changes l -> 1, and now the issue is:

    Runtime error 3142: unexpected character after the end of the SQL statement

    line:
    Code:
    Set MyRS = MyDB.OpenRecordset(strSQL, dbOpenForwardOnly)

  4. #79
    ingarchsf is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    50
    ok, I've moved the three "if" before the "strSQL".. and the Runtime error changes.. now is 3075: parethesis in excess: ) in the expression of the query '(Cognome Like "**") AND (N_corso = 4) AND (N_modulo = )'.

    I've entered only N_corso..

    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
        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
        
        'See if the string has more than 5 characters (a trailing " AND ") to remove.
        lngLen = Len(strWhere) - 5
        If lngLen > 0 Then
            'Yep: there is something there, so remove the " AND " at the end.
            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 & ";"
         strSQL = strSQL & " WHERE Cognome ='" & Me.qcognome1 & "' AND N_corso =" & Me.qncorso1 & " AND N_modulo =" & Me.qnmodulo1 & ""
        
        Set MyRS = MyDB.OpenRecordset(strSQL, dbOpenForwardOnly)
        
        With MyRS
            Do While Not MyRS.EOF
                sCriteria = "[Cognome]='" & ![Cognome] & "' and [Nome]='" & ![Nome] & "' and [Data_modulo] = #" & ![Data_modulo] & "#"
                DoCmd.OpenReport strRptName, acViewPreview, , sCriteria
                
                DoCmd.OutputTo acOutputReport, strRptName, acFormatPDF, "C:\Attestati\" & Format(![Cognome], ">") & Format(![Nome], "<") & "_" & Format(![Data_modulo], "YYYYMMDD") & ".pdf", False
                DoCmd.Close acReport, strRptName
                .MoveNext
            Loop
        End With
        MyRS.Close
        Set MyRS = Nothing
        MsgBox "Done"
    End Sub

  5. #80
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    When were the 3 "If" after strSQL???? Oh well, as long as in right place now.

    Why is the string including the parameters if there are no inputs?
    Are the input controls really null if nothing is entered?

    An alternative If to handle both Null and empty string:

    If Me.qcognome1 & "" <> "" Then

    Step debug, follow the code as it executes, one line at a time.
    What values are in the controls and variables as the code runs?
    Does the code process as expected for the inputs?
    Is the composed SQL statement correct? Can use a Debug.Print line to help view the string.
    Review link at bottom of my post for debugging guidelines.
    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.

  6. #81
    ingarchsf is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    50
    I've tried, but it does exactly the same..

    Runtime error 3142: unexpected character after the end of the SQL statement

    line:
    Code:
    Set MyRS = MyDB.OpenRecordset(strSQL, dbOpenForwardOnly)
    I've tried only with a value in one of the variables: I've put 1 in N_corso (qncorso1)
    The other variables have as default value ""

  7. #82
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Why do you still have this line:

    strSQL = strSQL & " 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.

  8. #83
    ingarchsf is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    50
    ehm.. Because in the base code given by ssanfu there was that line, that selects th values from the boxes..
    is the example there was only Cognome.. I added the other 2. If I insert all the three values, without if clauses, it works very well.. But if I insert only one value of the three, it gives error..

    see posts 58 and 62

  9. #84
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    But now you have the 3 If Then structures to conditionally build the WHERE clause. By keeping that old code the SQL could result in two WHERE clauses. The old line includes all 3 parameters even if there is no input. The flexibility of input is the reason for the conditional If Then structures. The old code line would then be eliminated. Can't have both in the same procedure - which is what you posted.
    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.

  10. #85
    ingarchsf is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    50
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    disabling that line, WORKS!!! *_*

    ok, it's almost perfect.. only one thing: at the beginning we started making a "search" button, following the first video example that you posted, but it was based on dynamic parameters, that can't be used now anymore.

    I'm thinking: making a "search button" has the same logic, isn't it? the aim, as previously, is to search pages of the report, based on the usual 3 parameters, but now to only visualize them all together as Preview. I tried to modify the CODE, removing the operations about exporting PDF, but it opens only one page.

  11. #86
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    A constructed WHERE clause could be used to set the form's Filter property. This is what Allen shows in his tutorial.

    The difference is the WHERE word would not be used.

    Also, constructed filter criteria (without the WHERE word) can be passed to report in OpenReport method.
    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.

  12. #87
    ingarchsf is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    50
    may I do something like this?

    Code:
     DoCmd.OpenReport strRptName, acViewPreview, , WHERE ....

  13. #88
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    The WHERE word is not used.

    DoCmd.OpenReport strRptName, acViewPreview, , strCriteria
    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.

  14. #89
    ingarchsf is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    50
    I've tried this way:

    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"
    but the error is: 3075, too many parenthesys in (Cognome = ) AND (N_corso = 1) AND (N_modulo = )

  15. #90
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    There are too many parens because the criteria are incomplete - there are no parameters.

    See post 80. Did you step debug? Why is the strWhere including the criteria if the controls have no input? If the controls are truly Null, the code should not include those criteria.

    You really need to learn debug techniques. Have you reviewed the link at bottom of my post?


    For sCriteria, do not use apostrophe delimiters with number type field parameters. If N_corso and N_modulo are number type fields, remove the apostrophes. Date type fields need # delimiter for parameters.
    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.

Page 6 of 7 FirstFirst 1234567 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 06-04-2014, 01:25 PM
  2. Export as PDF
    By lugnutmonkey in forum Import/Export Data
    Replies: 1
    Last Post: 02-19-2013, 11:23 AM
  3. Export to Word
    By Monterey_Manzer in forum Import/Export Data
    Replies: 0
    Last Post: 12-20-2012, 02:06 PM
  4. CSV Export
    By mchadwick in forum Access
    Replies: 1
    Last Post: 09-06-2011, 03:19 PM
  5. Export
    By vvasudev in forum Import/Export Data
    Replies: 2
    Last Post: 01-20-2010, 11:42 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