Results 1 to 10 of 10

Thread: Report Designer Query

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Location
    Western North Carolina
    Posts
    124

    Exclamation Report Designer Query

    I have a program that uses an Access database and the report designer built into VB 6.0.

    Now for the problem. I need to do a date range search using input from txtBeginDate (beginning date) and txtEndDate (ending date) text boxes. I want the report to show only the dates that fall between the beginning and ending dates that were selected by the user in the previous text boxes. So how do I do it ? Do I do an SQL Query ? How do I get only the desired information to print out to the report?

    Oh... my client does not want to use a full blown Crystal Report. (Don't want to have to buy Crystal....in other words)

    Can anyone help me out?

    Thanks


  2. #2
    Lively Member
    Join Date
    Sep 2001
    Location
    US
    Posts
    115
    take a look at the simple data environment thread and alter the sql string to your liking

    This code may give you a little more flexibility

    Hope this helps
    Pinkpanther

  3. #3
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    Something like this: (I did not type in IDE so there may be some small snytax errors)

    Code:
    'IN THE FORM
    Sub Command1_Click()
      Call DataReport1.sSetup(txtDate1.text,txtDate2.text)
    DataReport1.show
    End Sub
    
    'In the DataReport
    Public Sub sSetup(sDate as string, eDate as string)
    dim tmprs as adodb.recordset
    dim strSQL as string
    
    strSQL = "SELECT * FROM table where datefield between '" & sDate & "' and '" & eDate & "'"
    tmprs.open strSQL,objConn,adOpenForwardOnly, adLockReadOnly
    
    Set me.datasource = tmprs
    End Sub
    Hope this helps,

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Location
    Western North Carolina
    Posts
    124

    Question reply to Negative0

    The code to show the report is in a command buttons click event. So where should the parts of the code go? In the form load event or the command.click event?

    Sorry to ask a dumb question...

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Location
    Western North Carolina
    Posts
    124

    Arrow clarification

    where in the DataReport should this piece of code go?

    'In the DataReport
    Public Sub sSetup(sDate as string, eDate as string)
    dim tmprs as adodb.recordset
    dim strSQL as string

    strSQL = "SELECT * FROM table where datefield between '" & sDate & "' and '" & eDate & "'"
    tmprs.open strSQL,objConn,adOpenForwardOnly, adLockReadOnly

    Set me.datasource = tmprs
    End Sub

    Should this go in the form that is calling the report or in the DataReport_Initialize function, or should I create a function ? I am a little confused.

    Thanks for Your help.

  6. #6
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    The IN THE DATAREPORT code should go in the datareport as a new function call sSetup.

    The IN THE FORM code should go on the form that is calling the datareport where the dates are specified.

    Hope this clears it up,

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Location
    Western North Carolina
    Posts
    124

    Question 1 More Question....Neg 0

    when i tried running the program the operation stopped when it got to the Data Report code.

    It said that the objConn was not defined. Can You help me with this also?

    Thanks

  8. #8
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    Turtle,

    In response to your PM:

    What is objConn?

    objConn is a connection object. So if you have a connection object already out there for your database replace objConn with your connection name. If you do not have one you can set one up like this:

    Code:
    dim objConn as new adodb.connection
    objConn.Open   "Driver={Microsoft Access Driver (*.mdb)};" & _
                    "Dbq=C:\YourFile.mdb"
    Hope this helps,

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Location
    Western North Carolina
    Posts
    124

    Problem

    I keep coming up with an error...

    Object variable or with block variable not set

    and it highlights this piece of code

    tmprs.open strSQL,objConn,adOpenForwardOnly, adLockReadOnly

  10. #10
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    Change this line:

    Code:
    dim tmprs as adodb.recordset
    to

    Code:
    dim tmprs as new adodb.recordset
    The recordset object was dimmed but not created. The new keyword creates the object.

    Hope this helps,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width