|
-
Dec 5th, 2001, 10:49 AM
#1
Thread Starter
Lively Member
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
-
Dec 5th, 2001, 11:12 AM
#2
Lively Member
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
-
Dec 5th, 2001, 11:55 AM
#3
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,
-
Dec 5th, 2001, 12:04 PM
#4
Thread Starter
Lively Member
-
Dec 5th, 2001, 12:12 PM
#5
Thread Starter
Lively Member
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.
-
Dec 5th, 2001, 12:15 PM
#6
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,
-
Dec 5th, 2001, 12:22 PM
#7
Thread Starter
Lively Member
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
-
Dec 5th, 2001, 12:25 PM
#8
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,
-
Dec 5th, 2001, 02:31 PM
#9
Thread Starter
Lively Member
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
-
Dec 5th, 2001, 02:46 PM
#10
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|