Report Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • manoj9849967222
    New Member
    • Jul 2007
    • 48

    Report Problem

    Hi all

    I have a form named "Form1" which has two textboxes "Textbox1" & Textbox3" which is ment to enter dates & also a command button "command9"

    I have a report named "Report1" which is based on query. The query is working fine.

    what i want to do is when the command button is click i want to load the report between the two given dates in the "textbox1" & "Textbox3"

    I have tried but is not working. I have used the following codes

    Private Sub Command9_Click( )
    Dim stDocName
    Dim stLinkCriteria
    stDocName = "Report1"
    DoCmd.OpenRepor t stDocName, , , stLinkCriteria
    End Sub

    I hope i am missing something in the codes.

    Please help me out

    Regards
    Manoj.
  • margot
    New Member
    • Sep 2007
    • 48

    #2
    Hey, I have the same problem. However an easy exit is to do a query.

    You create a query with all the fields and on the Date field Type the code below.

    Between [Enter First Date ] And [Enter Last Date]

    Then you create a report based on the query that you just created. When someone clicks the report they should be able to enter the 2 dates and the report should be created.

    Hope this helps.

    Comment

    • kjworm
      New Member
      • Nov 2006
      • 26

      #3
      You could go the query route, but the missing item in your code is the definition of your stLinkCriteria similar to how you have stDocName="Repo rt1". You need to define this.

      Comment

      • Jim Doherty
        Recognized Expert Contributor
        • Aug 2007
        • 897

        #4
        Originally posted by manoj9849967222
        Hi all

        I have a form named "Form1" which has two textboxes "Textbox1" & Textbox3" which is ment to enter dates & also a command button "command9"

        I have a report named "Report1" which is based on query. The query is working fine.

        what i want to do is when the command button is click i want to load the report between the two given dates in the "textbox1" & "Textbox3"

        I have tried but is not working. I have used the following codes

        Private Sub Command9_Click( )
        Dim stDocName
        Dim stLinkCriteria
        stDocName = "Report1"
        DoCmd.OpenRepor t stDocName, , , stLinkCriteria
        End Sub

        I hope i am missing something in the codes.

        Please help me out

        Regards
        Manoj.

        You need to create the criteria string for the where clause argument for your report the dates of which are passed to the variable strLinkCriteria and formatted accordingly by the function FORMAT

        Code:
         
        Dim stDocName
        Dim stLinkCriteria
        strLinkCriteria = "#[NameOfYourField] Between #" & Format(Me!TextBox1, "mm/dd/yyyy")
        strLinkCriteria = strLinkCriteria & "# and #" & Format(Me!TextBox3, "mm/dd/yyyy") & "#"
        stDocName = "Report1"
        DoCmd.OpenReport stDocName, , , stLinkCriteria

        Regards

        Jim

        Comment

        • manoj9849967222
          New Member
          • Jul 2007
          • 48

          #5
          Hi Jim

          I am not able to view the report. It is directly going to the printer.

          Regards
          Manoj

          Comment

          • MMcCarthy
            Recognized Expert MVP
            • Aug 2006
            • 14387

            #6
            Originally posted by manoj9849967222
            Hi Jim

            I am not able to view the report. It is directly going to the printer.

            Regards
            Manoj
            Hi Manoj

            Change line 6 as follows:

            DoCmd.OpenRepor t stDocName, acViewPreview, , stLinkCriteria

            Comment

            Working...