0

I have a database which i have been able to design a form which enables me to search data in a date range and the results are display in a datasheet below it. I wish to be able to make the filtered results printable in a report.

Below are the vba codes i used for the form:


Private Sub Command20_Click()
' Search button
Call Search
End Sub
Sub Search()
Dim strCriteria, task As String

Me.Refresh
If IsNull(Me.OrderDateFrom) Or IsNull(Me.OrderDateTo) Then
    MsgBox "Please enter the date range", vbInformation, "Date Range Required"
    Me.OrderDateFrom.SetFocus

Else
    strCriteria = "([DATE] >= #" & Me.OrderDateFrom & "# And [DATE] <= #" & Me.OrderDateTo & "#)"
    task = "select * from ALL_INCOME where (" & strCriteria & ") order by [DATE]"
    DoCmd.ApplyFilter task
    
End If

Any help on how to get it into a printable report will be greatly appreciated.

PMF
  • 14,535
  • 3
  • 23
  • 49
Tete
  • 17
  • 4
  • Can you not just print the generated sheet? – mkrieger1 Apr 04 '21 at 13:42
  • Please can you demonstrate or explain further? – Tete Apr 04 '21 at 13:59
  • 1
    Press Ctrl-p and print the sheet you are able to generate with this code. If this is not what you want, please edit the question and clarify what is the programming problem you are facing. – mkrieger1 Apr 04 '21 at 14:03
  • Create a query, and base a report on it. You can either set the `.SQL` of the query as required, or use the two form controls as filters for the query. Note that `Date` is a reserved word in Access, so you really should change it. – Applecore Apr 04 '21 at 15:01
  • Please how do I go about that? Can you show me? – Tete Apr 04 '21 at 16:44
  • 1
    Does this answer your question? [MS Access - Docmd.OpenReport](https://stackoverflow.com/questions/50346797/ms-access-docmd-openreport). Instead of `acViewReport`, use `acViewNormal` for direct to printer. – June7 Apr 04 '21 at 16:58
  • Please am not so good with this. This is why I sent the codes i used for mine. Can you demonstrate using the codes I sent here on how am going to go about it – Tete Apr 04 '21 at 17:11
  • The example is quite clear. You already have most of the necessary code. Make an attempt. If still having issue, edit your question with that attempt or start a new question. – June7 Apr 04 '21 at 18:02
  • Sorry but am still finding difficulties please – Tete Apr 04 '21 at 21:42
  • Are you going to add a new button for printing? If not, then let us know how the user does the printing, so we can suggest where to put some code. – tgolisch Apr 06 '21 at 15:34
  • Please I will like to add a new button for the printing – Tete Apr 07 '21 at 05:24
  • Still waiting for your response @tgolisch – Tete Apr 24 '21 at 11:57
  • Can you use the form editor to add a button, and then add code to the button (events, onclick) to run `Docmd.OpenReport` like June7 suggested? – tgolisch Apr 26 '21 at 12:56

0 Answers0