Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Xiaoding is offline Novice
    Windows 2K Access 2003
    Join Date
    Nov 2009
    Posts
    29

    Sending Results of Querty to Report

    Hi All,



    I have a data entry form with 18 text boxes, used for entering criteria for a query.

    Right now, when my query runs, it runs for all 18 boxes, even if 17 of them have zero's, which don't need to be run.

    So, instead of running one query, that runs all boxes, I am using if/then and goto statements to check the text boxes for zero, and if it is a zero, to GOTO the sql query I have written further down. So I have 17 sql querys written, and depending on how many boxes have actual data, the program jumps to the appropriate sql query. I am trying to keep it simple, this is my first foray into SQL.

    My question is, how to pass the data generated by the query, to a report. As I understand it, the SQL generates a record set. So, I need to get that recordset to the report. Or am I doing this all wrong?

    thnx


  2. #2
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    18 queries!!!!???? Just for 1 report?????

    We need to fix that!!!


    My question is, how to pass the data generated by the query, to a report. As I understand it, the SQL generates a record set. So, I need to get that recordset to the report. Or am I doing this all wrong?
    A report is bound to a table or query (the record source). The records can be limited for the report by using a filter (the WHERE clause). One way of doing this is to change the SQL "on-the-fly". You can modify the query def of the report or change the report record source to a different query.

    The way I prefer is to use a basic query for the report record source. Just a standard "SELECT field1, field2, ... FROM MyTable" type of SQL string.

    Using VBA, I get the parameters from a form and create a "WHERE" clause (without the WHERE). Then I use the "Docmd.Openreport" command to open the report. Below is a snippet of the code.

    Code:
    'Purpose:   Build up the criteria string form the non-blank search boxes, and apply to the form's Filter.
    'Notes:     1. We tack " AND " on the end of each condition so you can easily add more search boxes; _
      we remove the last trailing " AND " at the end.
    '           2. The date range works like this: _
                Both dates      = only dates between (both inclusive. _
                Start date only = all dates from this one onwards; _
                End date only   = all dates up to (and including this one).
       Dim strWhere As String                  'The criteria string.
       Dim lngLen As Long                      'Length of the criteria string to append to.
       Const conJetDate = "\#mm\/dd\/yyyy\#"   'The format expected for dates in a JET query string.
    
    '***********************************************************************
    'Look at each search box, and build up the criteria string from the non-blank ones.
    '***********************************************************************
    ------<snip>--------
    
    ------<snip>--------
       'DOB - Date field example. Use the format string to add the # delimiters and get the right international format.
       If Not IsNull(Me.tbDOB) Then
          strWhere = strWhere & "([end_dob] = " & Format(Me.tbDOB, conJetDate) & ") AND "
       End If
    
       'cboCity - Text field example.
       If Not IsNull(Me.cboCity) Then
          strWhere = strWhere & "([end_city] = '" & Me.cboCity & "') AND "
       End If
    
       'cboState - Text field example.
       If Not IsNull(Me.cboState) Then
          strWhere = strWhere & "([end_state] = '" & Me.cboState & "') AND "
       End If
    
       'cboZip - Text field example.
       If Not IsNull(Me.cboZip) Then
          strWhere = strWhere & "([end_zip] = '" & Me.cboZip & "') AND "
       End If
    
       '***********************************************************************
       'Chop off the trailing " AND ", and use the string as the form's Filter.
       '***********************************************************************
       'See if the string has more than 5 characters (a trailng " AND ") to remove.
       lngLen = Len(Trim(strWhere)) - 4
       If lngLen <= 0 Then     'Nah: there was nothing in the string.
          MsgBox "No criteria", vbInformation, "Nothing to do."
       Else                    'Yep: there is something there, so remove the " AND " at the end.
          strWhere = Left$(strWhere, lngLen)
    
    'open the report on preview mode
    ' "lstForm" is a list box thst holds the report names
    '  "strWhere" is the criteria
    
          DoCmd.OpenReport lstForm, acViewPreview, , strWhere
    ------<snip>--------
    Using this approach, you can limit the records any way you want. If you get stuck, attach a zip file of the queries (the SQL for 18 queries is too much to post inline. ) and I will try and whip up some code for you.

  3. #3
    Xiaoding is offline Novice
    Windows 2K Access 2003
    Join Date
    Nov 2009
    Posts
    29

    Thnx!

    Thank you very much for your reply, SSanfu, you set in the right direction. I'm sorry it took so long for me to reply, I had to set this on the back burner at work.

    I learned the dynamic report technique, here is the code I use now:




    Option Compare Database
    Option Explicit
    Private Sub cmd18_Click()
    On Error GoTo Err_cmd18
    Dim strFilter As String
    Dim SQL1 As String
    Dim SQL8 As String
    Dim SQL9 As String
    Dim SQL10 As String
    Dim SQL11 As String
    Dim SQL12 As String
    Dim SQL13 As String
    Dim SQL14 As String
    Dim SQL15 As String
    Dim SQL16 As String
    Dim SQL17 As String
    Dim SQL18 As String


    SQL1 = "aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt1] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm'
    Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt2] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm'
    Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt3] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm'
    Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt4] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm'
    Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt5] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm'
    Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt6] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm'
    Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt7] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm'"

    SQL8 = " Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt8] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm'"

    SQL9 = "Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt9] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm'"

    SQL10 = "Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt10] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm'"

    SQL11 = "Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt11] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm'"

    SQL12 = "Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt12] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm'"

    SQL13 = "Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt13] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm'"

    SQL14 = "Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt14] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm'"

    SQL15 = "Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt15] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm'"

    SQL16 = "Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt16] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm'"

    SQL17 = "Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt17] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm'"

    SQL18 = "Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt18] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm'"

    If [Forms]![frm18]![txt2] = 0 Then GoTo Q1
    If [Forms]![frm18]![txt3] = 0 Then GoTo Q2
    If [Forms]![frm18]![txt4] = 0 Then GoTo Q3
    If [Forms]![frm18]![txt5] = 0 Then GoTo Q4
    If [Forms]![frm18]![txt6] = 0 Then GoTo Q5
    If [Forms]![frm18]![txt7] = 0 Then GoTo Q6
    If [Forms]![frm18]![txt8] = 0 Then GoTo Q7
    If [Forms]![frm18]![txt9] = 0 Then GoTo Q8
    'If [Forms]![frm18]![txt10] = 0 Then GoTo Q9
    'If [Forms]![frm18]![txt11] = 0 Then GoTo Q10
    'If [Forms]![frm18]![txt12] = 0 Then GoTo Q11
    'If [Forms]![frm18]![txt13] = 0 Then GoTo Q12
    'If [Forms]![frm18]![txt14] = 0 Then GoTo Q13
    'If [Forms]![frm18]![txt15] = 0 Then GoTo Q14
    'If [Forms]![frm18]![txt16] = 0 Then GoTo Q15
    'If [Forms]![frm18]![txt17] = 0 Then GoTo Q16
    'If [Forms]![frm18]![txt18] = 0 Then GoTo Q17

    'GoTo Q18
    Exit Sub

    Q1:
    ' trying single quotes in below for the field criteria, double quotes causing problems.
    strFilter = "aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt1] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm'"

    GoTo Report
    Exit Sub

    Q2:
    strFilter = "aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt1] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm' Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt2] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm'"
    GoTo Report
    Exit Sub

    Q3:
    strFilter = "aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt1] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm' Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt2] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm' Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt3] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm'"
    GoTo Report
    Exit Sub

    Q4:
    strFilter = "aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt1] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm' Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt2] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm' Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt3] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm' Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt4] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm'"
    GoTo Report
    Exit Sub

    Q5:
    strFilter = "aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt1] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm' Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt2] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm' Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt3] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm' Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt4] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm' Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt5] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm'"
    GoTo Report
    Exit Sub

    Q6:
    strFilter = "aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt1] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm' Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt2] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm' Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt3] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm' Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt4] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm' Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt5] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm' Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt6] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm'"

    GoTo Report
    Exit Sub

    Q7:
    strFilter = "aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt1] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm' Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt2] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm' Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt3] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm' Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt4] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm' Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt5] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm' Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt6] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm' Or aims_WKO.TAG_NUMBER=[Forms]![frm18]![txt7] AND aims_WCT.RESPONSE Like '006' AND aims_EQU.EQU_STATUS='I' AND aims_WKO.WO_TYPE='pm'"

    GoTo Report
    Exit Sub

    Q8:
    strFilter = SQL1 & SQL8
    GoTo Report
    Exit Sub

    Q9:
    strFilter = SQL1 & SQL8 & SQL9
    GoTo Report
    Exit Sub

    Q10:
    strFilter = SQL1 & SQL8 & SQL9 & SQL10
    GoTo Report
    Exit Sub

    Q11:
    strFilter = SQL1 & SQL8 & SQL9 & SQL10 & SQL11
    GoTo Report
    Exit Sub

    Q12:
    strFilter = SQL1 & SQL8 & SQL9 & SQL10 & SQL11 & SQL12
    GoTo Report
    Exit Sub

    Q13:
    strFilter = SQL1 & SQL8 & SQL9 & SQL10 & SQL11 & SQL12 & SQL13
    GoTo Report
    Exit Sub

    Q14:
    strFilter = SQL1 & SQL8 & SQL9 & SQL10 & SQL11 & SQL12 & SQL13 & SQL14
    GoTo Report
    Exit Sub

    Q15:
    strFilter = SQL1 & SQL8 & SQL9 & SQL10 & SQL11 & SQL12 & SQL13 & SQL14 & SQL15
    GoTo Report
    Exit Sub

    Q16:
    strFilter = SQL1 & SQL8 & SQL9 & SQL10 & SQL11 & SQL12 & SQL13 & SQL14 & SQL15 & SQL16
    GoTo Report
    Exit Sub

    Q17:
    strFilter = SQL1 & SQL8 & SQL9 & SQL10 & SQL11 & SQL12 & SQL13 & SQL14 & SQL15 & SQL16 & SQL17
    GoTo Report
    Exit Sub

    Q18:
    strFilter = SQL1 & SQL8 & SQL9 & SQL10 & SQL11 & SQL12 & SQL13 & SQL14 & SQL15 & SQL16 & SQL17 & SQL18
    GoTo Report
    Exit Sub

    Report:
    DoCmd.OpenReport "RPT18", acViewPreview, "QRY18", strFilter

    Exit Sub

    Err_cmd18:
    MsgBox Err.Description
    'resume cmd18_Click()

    Exit Sub

    End Sub
    Private Sub cmdEquipmentNotFoundWorkOrdersReport_Click()
    End Sub



    As you can see, just a bunch of If/thens, then the chosen WHERE statement is sent to to the report.

    It works fine, unitil I input nine entries in the text boxes. This causes the code to select the option Q9, and there is a problem with that. When I click on the button on the form, with nine entries, the button clicks, but nothing happens. No error message, nothing! With eight entries, no problem, I get the report just fine.

    I'm scratching my head on this one, anyone see the problem?

  4. #4
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Holy crap Batman! This is ludicrous. Sorry to say but you did NOT learn how to dynamically do this. You created a monster.

    You can shorten your code down to this:
    Code:
    Private Sub cmd18_Click()
        On Error GoTo Err_cmd18
     
        Dim strFilter As String
        Dim strHold As String
        Dim intCount As Integer
     
        intCount = 1
     
        Do Until intCount = 19
            If Len(Me.Controls("txt" & intCount).Value & vbNullString) > 0 Then
                strHold = Me.Controls("txt" & intCount).Value & ","
            End If
            intCount = intCount + 1
        Loop
     
        If Left(strHold, 2) = ", " Then
            strHold = Left(strHold, Len(strHold) - 2)
        End If
     
        strFilter = "[aims_WKO].[TAG_NUMBER] In(" & strHold & ") AND aims_WCT.RESPONSE = '006' AND aims_EQU.EQU_STATUS = 'I' AND aims_WKO.WO_TYPE='pm'"
     
        DoCmd.OpenReport "RPT18", acViewPreview, , strFilter
     
    cmd18_ExitHere:
        Exit Sub
     
    Err_cmd18:
        MsgBox Err.Description
        Resume cmd18_ExitHere
     
    End Sub
    Last edited by boblarson; 06-10-2011 at 03:27 PM. Reason: added intCount = 1 otherwise it would error out.

  5. #5
    khalid's Avatar
    khalid is offline MS-Access Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2010
    Location
    Kuwait
    Posts
    244
    Great Bob
    This is called the dynamic query
    What this bit actually do?
    & vbNullString) > 0
    and this one:
    Left(strHold, Len(strHold) - 2) (remove the extra ,) ?

  6. #6
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Quote Originally Posted by khalid View Post
    Great Bob
    This is called the dynamic query
    What this bit actually do?
    & vbNullString) > 0
    When using LEN you will get an error with a NULL so you append an empty string on it and then it will also check for an empty string as well as a null.
    and this one:
    Left(strHold, Len(strHold) - 2) (remove the extra ,) ?
    Yes, removes the extra comma and space at the end.

  7. #7
    khalid's Avatar
    khalid is offline MS-Access Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2010
    Location
    Kuwait
    Posts
    244
    Thanks bob so I can change my title to AWF VIP

    @Xiaoding - bob is always great dude
    Last edited by khalid; 06-10-2011 at 04:14 PM. Reason: typo, due >> dude

  8. #8
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Quote Originally Posted by khalid View Post
    Thanks bob so I can change my title to AWF VIP
    Sorry, not quite yet.

  9. #9
    khalid's Avatar
    khalid is offline MS-Access Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2010
    Location
    Kuwait
    Posts
    244
    Its okay bob, one day I will be Inshallah, have to wait little more, but the problem is I am so busy with my office schedule and development don't have enough time to solve forum's problems.

  10. #10
    Xiaoding is offline Novice
    Windows 2K Access 2003
    Join Date
    Nov 2009
    Posts
    29

    Re:

    Thanks so much for your reply, Bob, it's given me a lot to look at!

    I stuck the code into the form, and I'm getting a "Data type mismatch in criteria expression" when I run it...of course, I can't spot the problem, any ideas?



    thnx!

    Xiaoding

  11. #11
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Quote Originally Posted by Xiaoding View Post
    Thanks so much for your reply, Bob, it's given me a lot to look at!

    I stuck the code into the form, and I'm getting a "Data type mismatch in criteria expression" when I run it...of course, I can't spot the problem, any ideas?



    thnx!

    Xiaoding
    On which line does it error out? Disable the error handler temporarily and then hit debug on the message that comes up when it errors.

  12. #12
    Xiaoding is offline Novice
    Windows 2K Access 2003
    Join Date
    Nov 2009
    Posts
    29

    re:

    thnx for your reply, Bob!

    "Disable the error handler temporarily and then hit debug on the message that comes up when it errors. "

    So THAT'S how you get it to do that!

    It pointed to "DoCmd.OpenReport "RPT18", acViewPreview, , strFilter",
    so I looked at strFilter.

    strFilter = "[aims_WKO].[TAG_NUMBER]In(" & strHold & ") AND aims_WCT.RESPONSE = '006' AND aims_EQU.EQU_STATUS = 'I' AND aims_WKO.WO_TYPE='pm'"

    Should there be an = sign between [TAG_NUMBER] and IN(? I added one, and got a different error message: Run time error 3075, syntax error (missing operator) in that same strfilter. Maybe is doesn't like the = sign...still, it must in in that area, because all the other criteria seems pretty simple.

    thnx,

    Xiaoding











    strFilter = "[aims_WKO].[TAG_NUMBER]= In(" & strHold & ") AND aims_WCT.RESPONSE = '006' AND aims_EQU.EQU_STATUS = 'I' AND aims_WKO.WO_TYPE='pm'"

    DoCmd.OpenReport "RPT18", acViewPreview, , strFilter

  13. #13
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    If you use IN you don't use =
    For some reason we aren't getting the space between [TAG_NUMBER] and IN


    So I have an IDEA. Try this:
    Code:
    Private Sub cmd18_Click()
        On Error GoTo Err_cmd18
     
        Dim strFilter As String
        Dim strHold As String
        Dim intCount As Integer
     
        intCount = 1
     
        Do Until intCount = 19
            If Len(Me.Controls("txt" & intCount).Value & vbNullString) > 0 Then
                strHold = Me.Controls("txt" & intCount).Value & ","
            End If
            intCount = intCount + 1
        Loop
     
        If Left(strHold, 2) = ", " Then
            strHold = Left(strHold, Len(strHold) - 2)
        End If
        strHold = " In(" & strHold & ")"
        strFilter = "[aims_WKO].[TAG_NUMBER] " & strHold & " AND aims_WCT.RESPONSE = '006' AND aims_EQU.EQU_STATUS = 'I' AND aims_WKO.WO_TYPE='pm'"
     
        DoCmd.OpenReport "RPT18", acViewPreview, , strFilter
     
    cmd18_ExitHere:
        Exit Sub
     
    Err_cmd18:
        MsgBox Err.Description
        Resume cmd18_ExitHere
     
    End Sub

  14. #14
    Xiaoding is offline Novice
    Windows 2K Access 2003
    Join Date
    Nov 2009
    Posts
    29

    Re :)

    Sorry, my goof, the lack of a space was not the issue, I posted that by mistake. Get the same error with or without the space.

    I don't think the text value is getting through, would be my guess right now.

  15. #15
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Is the field [TAG_NUMBER] really a number or is it text?

    Also, not only the space but did you remove the = sign? Because it should not be

    = IN(.....etc.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Strange report results
    By DDows in forum Reports
    Replies: 5
    Last Post: 01-10-2011, 06:43 PM
  2. Replies: 2
    Last Post: 08-17-2010, 10:54 AM
  3. Replies: 0
    Last Post: 07-06-2010, 08:12 AM
  4. Limiting the results displayed in a report
    By musicalogist in forum Reports
    Replies: 1
    Last Post: 06-10-2010, 04:44 PM
  5. Replies: 3
    Last Post: 05-21-2010, 03:57 PM

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