473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

.Openreport method NOT printing ALL records from a filtered form, why?

39
I am using Access 2003 on XP Professional 2003 platform. I have been

struggling with what appears to be a relatively easy coding problem.

I am unable to get my VBA code to show all the records and allow me to

view the filtered responses from user input, once my cmd_click() event

fires.

The form displays the 19 fields from database in an AD HOC form, using a

continuous form format so it allows the user to select what fields they want

to filter.

To aid the user, I have two unbound combo boxes and four unbound text

boxes for user input:

Program name (Combo)
Source (Text)
Liaison (Text)
Status (Combo)
Due Date - From (Text)
Due Date - To (Text)

The filter works great. However, it only displays the FIRST record on the
report. What am I doing incorrectly?

Dim stDocName As String
Dim strWhere As String 'The criteria string.

stDocName = "rptActionItems_Filtered"
DoCmd.OpenReport stDocName, acViewPreview, strWhere

Thanks,
Apr 22 '10 #1

✓ answered by TheSmileyCoder

IF I had to guess, you probably had a WHERE clause in the recordsource of the report limiting it by a single field in the form, thus only showing 1 record.

Anyways, glad you got it to work.

7 2323
TheSmileyCoder
2,322 Expert Mod 2GB
Welcome to Bytes

If you open the report directly, does it show all the records? If not, problem is likely in the recordsource of the report.

If it does, problem might be in the strWhere. Do you actually use this? From the code you posted I dont see anything about it.
Apr 23 '10 #2
Qtip23
39
@TheSmileyOne
Hey there,

Well the report pulls the data from the criteria string based on the table. I do not have any issues with that as the user can easily see his/her selection when they scroll down on the continuous form.

I modified code I found from Adapted from: http://allenbrowne.com to suit my requirement.

I have a button that fires the filtering,here is the code associated:

Private Sub cmdFilter_Click()
On Error GoTo Err_cmdFilter_Click

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.


If Not IsNull(Me.txtFilterLiaison) Then
strWhere = strWhere & "([Liaison_Contact_Information] = """ & Me.txtFilterLiaison & """) AND "
End If

If Not IsNull(Me.txtFilterSource) Then
strWhere = strWhere & "([Source] Like ""*" & Me.txtFilterSource & "*"") AND "
End If

If Not IsNull(Me.cboFilterProgram) Then
strWhere = strWhere & "([Program] Like ""*" & Me.cboFilterProgram & "*"") AND "
End If

If Not IsNull(Me.cboFilterStatus) Then
strWhere = strWhere & "([Status] Like ""*" & Me.cboFilterStatus & "*"") AND "
End If

If Not IsNull(Me.txtStartFilterDate) Then
strWhere = strWhere & "([Due_Date] >= " & Format(Me.txtStartFilterDate, conJetDate) & ") AND "
End If

If Not IsNull(Me.txtEndFilterDate) Then 'Less than the next day.
strWhere = strWhere & "([Due_Date] < " & Format(Me.txtEndFilterDate + 1, conJetDate) & ") AND "
End If

lngLen = Len(strWhere) - 5
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)
'For debugging, remove the leading quote on the next line. Prints to Immediate Window (Ctrl+G).
Debug.Print strWhere

'Finally, apply the string as the form's Filter.
Me.Filter = strWhere
Me.FilterOn = True
End If


Exit_cmdFilter_Click:
Exit Sub

Err_cmdFilter_Click:
MsgBox Err.Description
Resume Exit_cmdFilter_Click



End Sub

Any advise would be greatly appreciated. Thx.
Apr 23 '10 #3
TheSmileyCoder
2,322 Expert Mod 2GB
Your report and form is based on the same recordsource?

Please use [code][/code] tags around your code.
Apr 23 '10 #4
Qtip23
39
Thanks. I will definitely use the code tags in the future to delineate the start so I am reposting with the tags.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdFilter_Click()
  2. On Error GoTo Err_cmdFilter_Click
  3.  
  4. Dim strWhere As String [comment]'The criteria string.[/comment]
  5. Dim lngLen As Long [comment]'Length of the criteria string to append to.[/comment]
  6. Const conJetDate = "\#mm\/dd\/yyyy\#" [comment]'The format expected for dates in a JET query string.[/comment]
  7.  
  8.  
  9. If Not IsNull(Me.txtFilterLiaison) Then
  10. strWhere = strWhere & "([Liaison_Contact_Information] = """ & Me.txtFilterLiaison & """) AND "
  11. End If
  12.  
  13. If Not IsNull(Me.txtFilterSource) Then
  14. strWhere = strWhere & "([Source] Like ""*" & Me.txtFilterSource & "*"") AND "
  15. End If
  16.  
  17. If Not IsNull(Me.cboFilterProgram) Then
  18. strWhere = strWhere & "([Program] Like ""*" & Me.cboFilterProgram & "*"") AND "
  19. End If
  20.  
  21. If Not IsNull(Me.cboFilterStatus) Then
  22. strWhere = strWhere & "([Status] Like ""*" & Me.cboFilterStatus & "*"") AND "
  23. End If
  24.  
  25. If Not IsNull(Me.txtStartFilterDate) Then
  26. strWhere = strWhere & "([Due_Date] >= " & Format(Me.txtStartFilterDate, conJetDate) & ") AND "
  27. End If
  28.  
  29. If Not IsNull(Me.txtEndFilterDate) Then 'Less than the next day.
  30. strWhere = strWhere & "([Due_Date] < " & Format(Me.txtEndFilterDate + 1, conJetDate) & ") AND "
  31. End If
  32.  
  33.  
  34. lngLen = Len(strWhere) - 5
  35. If lngLen <= 0 Then [comment]'Nah: there was nothing in the string.[/comment]
  36. MsgBox "No criteria", vbInformation, "Nothing to do."
  37. Else 'Yep: there is something there, so remove the " AND " at the end.
  38. strWhere = Left$(strWhere, lngLen)
  39.  
  40. [comment]'For debugging, remove the leading quote on the next line. Prints to Immediate Window (Ctrl+G).[/comment]
  41.  
  42. Debug.Print strWhere
  43.  
  44. [comment] 'Finally, apply the string as the form's Filter.[/comment]
  45. Me.Filter = strWhere
  46. Me.FilterOn = True
  47. End If
  48.  
  49.  
  50. Exit_cmdFilter_Click:
  51. Exit Sub
  52.  
  53. Err_cmdFilter_Click:
  54. MsgBox Err.Description
  55. Resume Exit_cmdFilter_Click
  56.  
  57.  
  58.  
  59. End Sub
  60.  
  61.  



The form is based on the recordsource. I believe the report is also based on
the recordsource as it does successfully display the criteria search in the form. When it is time to print, only one record is visible at preview (depending where the arrow is pointing from the continuous-form.)

I even tried changing the sorting and grouping field expression to point to the InternalID field (in ascending order) since that is the primary key of the table.
Apr 23 '10 #5
Qtip23
39
@Qtip23
While the report appeared to be based on the same recordsource, I started from scratch and went to the report design wizard to ensure all fields where pointing to the correct control source. Voila! It works now.

I tell you...most times, it's the little things. Thx TheSmileyOne.
Apr 26 '10 #6
TheSmileyCoder
2,322 Expert Mod 2GB
IF I had to guess, you probably had a WHERE clause in the recordsource of the report limiting it by a single field in the form, thus only showing 1 record.

Anyways, glad you got it to work.
Apr 27 '10 #7
Qtip23
39
@TheSmileyOne
Hello TheSmileyOne,

Wow, did I goof big time?! I actually had time to review my code and realized that while the form still filters properly (according to the criteria), I cannot view ALL the variables in the report once I fire the click button. Please help!
May 7 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Aaron | last post by:
Hello, I'm trying to limit a report to a list of parameters that I pass in. The report and the underlying query both use the column FirstName. Whenever I try to limit the FirstName in via the...
3
by: Blah | last post by:
Hello, I'm trying to use the where clause in OpenReport to limit the data return on the subreport. Is there a way to do it using that method or OpenReport only work with the report you're...
2
by: origin197511 | last post by:
Hello all... I'm having an issue with MSAccess 2000. I have a Form that holds records of my cartridge loads for a rifle and a subform that lists all groups that have been fired with that load. ...
2
by: Zeljko | last post by:
I'm creating Address book. Header of the main form (frmAddress) contains combo box (cboFilter) to filter records by Occupation on main Form(Ocupation1). That's working. Combo box also have "Show...
1
by: Jimmy Stewart | last post by:
I have a continuous form with a list of items from a table. One of the fields in the table is "print". this allows the user to select items from the list on the form for printing in a report. on...
0
by: Ironr4ge | last post by:
Hi everyone, By the rate its going it want be long till I start growing gray hair... but anyway.. to come to the point... I am trying to open the form "Languages" with a diffrent record...
4
by: Ironr4ge | last post by:
Hi everyone, I am trying to open the form "Languages" with a diffrent record source to the "Contacts" form where I conducted the search or filter... . I was wondering whether there was a vba...
0
by: ramseyscripts | last post by:
I have Table A that is displayed through a form. Table A can be filtered through the form to create a subset of Table A records. How can I create a new table, Table B, with only the records in the...
6
by: Nettle | last post by:
Purpose: I am creating a mailing distribution list database. Users should be able to filter/search contacts and add them to distribution lists they have created. My problem? I can't add multiple,...
6
jinalpatel
by: jinalpatel | last post by:
I am using following code for searching records. '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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.