Page 5 of 7 FirstFirst 1234567 LastLast
Results 61 to 75 of 100
  1. #61
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Remove that last quote mark. It is not in my example.
    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.

  2. #62
    ingarchsf is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    50
    ok, sorry!

    Now.. it works only if I write all the three parameters.. but.. if I use only one parameter, it tells "missing operator"..
    is there any way to solve? like.. the "Like... & "*"" that we put previously in the query?

  3. #63
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    I don't use dynamic parameter queries. And the LIKE with wildcard only works with text fields, not number type fields.

    I would use VBA code to conditionally build the filter string. Review: http://www.allenbrowne.com/ser-62code.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.

  4. #64
    ingarchsf is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    50
    Quote Originally Posted by June7 View Post
    I don't use dynamic parameter queries. And the LIKE with wildcard only works with text fields, not number type fields.

    I would use VBA code to conditionally build the filter string. Review: http://www.allenbrowne.com/ser-62code.html
    uhm.. but previously inside the query worked also for numeric field!!

    btw.. I've understood through that link that I should use an "if".. can I use the "if.. then" inside WHERE? I remember that in Pascal syntax it was possible..

  5. #65
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    If used with number field, LIKE 1* should return 1, 10, 11, 100, etc. If your data never exceeds the number 9, then the LIKE and wildcard is fine.

    I think IIf() in criteria of query object is possible but tricky. I don't use dynamic parameters in queries at all.
    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. #66
    ingarchsf is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    50
    uhm... ooooooooooooook..
    so.. any way to let the CODE know that "if you don't see any value in that field, don't worry.. you could use the other two!!!" :P

  7. #67
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Post 63 references an Allen Browne article with example VBA code to accomplish that.
    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. #68
    ingarchsf is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    50
    Quote Originally Posted by June7 View Post
    Post 63 references an Allen Browne article with example VBA code to accomplish that.
    June7.. I don't know how to use it!! I could read it as much as I want, but I have no idea of how to use it!..

  9. #69
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Did you read the Search Criteria article that Allen References at the top of his page? It has a sample database you can download to learn from.
    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. #70
    ingarchsf is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    50
    Quote Originally Posted by June7 View Post
    Did you read the Search Criteria article that Allen References at the top of his page? It has a sample database you can download to learn from.
    yes, I've read it.. but.. I don't know where to put any of those.. how to edit any of those.. I have 3 fields..

  11. #71
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Allen's example builds criteria to set form Filter property. The code is in a button Click event. Did you explore the sample database?

    Adapt code to your requirements. What is it you do not understand about programming with VBA and adapting example code? Haven't you been able to adapt other example code, such as from database provided by ssanfu? Why can't you do that with Allen's example? Use whatever parts you need. You need 3 parameters then you need 3 If Then structures. Instead of setting form Filter property, use the constructed criteria string in the WHERE clause of the SQL statement for the recordset.

    Use whichever of Allen's If Then examples are appropriate and fill in the blanks:
    Code:
    Private Sub ExportPDF_Click()
    Dim ...
    
    If ... Then
    ...
    End If
    
    If ... Then
    ...
    End If
    
    If ... Then
    ...
    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] From Selezione_corso_2014 " & strWhere & ";"
        Set MyRS = MyDB.OpenRecordset(strSQL, dbOpenForwardOnly)  
        With MyRS
            ...
        End With
    ...
    End Sub
    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. #72
    ingarchsf is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    50
    uhm.. problem: impossible to find the method (syntax error) on Me.qncorso1 (number) inside the second If.. [and the same on Me.qnmodulo1 (number) inside the third If..

    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                  'The criteria string.
        Dim lngLen As Long                      'Length of the criteria string to append to.
    
        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.qncorsol) Then
            strWhere = strWhere & "([N_corso] = " & Me.qncorsol & ") AND "
        End If
        
        If Not IsNull(Me.qnmodulol) Then
            strWhere = strWhere & "([N_modulo] = " & Me.qnmodulol & ") 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
        
        'OLD SQL
        '    strSQL = "Select Selezione_corso_2014.[Cognome], Selezione_corso_2014.[Data_modulo] From Selezione_corso_2014;"
        ' this query selects all records with the surname entered in Me.txtCognome   (Form1.txtCognome)
        ' You would need to modify this to maybe include dates if you didn't want to re export previously
        ' exported records.
        strSQL = "Select Selezione_corso_2014.[Cognome], Selezione_corso_2014.[Data_modulo] From Selezione_corso_2014 " & strWhere & ";"
        ' strSQL = strSQL & " WHERE Cognome ='" & Me.qcognome1 & "' AND N_corso =" & Me.qncorso1 & " "
        Set MyRS = MyDB.OpenRecordset(strSQL, dbOpenForwardOnly)
        
    '    Application.Echo False
        
        With MyRS
            Do While Not MyRS.EOF
                'create the criteria string              '   "Cognome" is a text field, "Data_modulo" is a date field.
                sCriteria = "[Cognome]='" & ![Cognome] & "' and [Data_modulo] = #" & ![Data_modulo] & "#"
                DoCmd.OpenReport strRptName, acViewPreview, , sCriteria
                
                'now output the report
                DoCmd.OutputTo acOutputReport, strRptName, acFormatPDF, "C:\Attestati\" & ![Cognome] & "_" & Format(![Data_modulo], "YYYYMMDD") & ".pdf", False
                DoCmd.Close acReport, strRptName
                .MoveNext
            Loop
        End With
    '    Application.Echo True
        MyRS.Close
        Set MyRS = Nothing
        MsgBox "Done"
    End Sub
    Last edited by ingarchsf; 09-01-2014 at 07:40 AM.

  13. #73
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    N_corso and N_modulo are number type fields? I don't see anything wrong with the code syntax. But I thought modulo was a date/time type?
    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. #74
    ingarchsf is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    50
    no, only number fields, no date fields!

  15. #75
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Then why is Data_modulo formatted as a date in the report criteria?

    Still no idea why the code errors. If you want to provide latest version of db ...
    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 5 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