Welcome to Dream.In.Code
Become a VB Expert!

Join 149,407 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,187 people online right now. Registration is fast and FREE... Join Now!




Pass varible from Form to DataReport

 
Reply to this topicStart new topic

Pass varible from Form to DataReport

ADiecidue
28 Jan, 2008 - 10:57 AM
Post #1

New D.I.C Head
*

Joined: 28 Jan, 2008
Posts: 2

I have a VB6 project with a single Form and DataReport. The DataReport is based on a DataEnvironment that points to an Access2003 database. The database has a single table with one of the fields being a Unique Identifier. I have a button on the form that opens the DataReport. The Datareport shows all the records in the database. I want it to be filtered by the Unique Identifier contained in the form's textbox. I've tried writting a SQL statement like this:

CODE
SELECT * FROM Orders WHERE CustID = form1.text1.text
,

but it doesn't work. Can anyone help me with this?
--Tony--
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Pass Varible From Form To DataReport
28 Jan, 2008 - 11:24 AM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,654



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
You say it doesn't work, can you give us any idea why? Does it generate an error message and what is that message? Does it simply not do anything? Does it show incorrect values in the DataReport? Does it clear the DataReport results? What makes you believe it is not working?

Help us help you. Thanks! smile.gif
User is offlineProfile CardPM
+Quote Post

ADiecidue
RE: Pass Varible From Form To DataReport
28 Jan, 2008 - 12:56 PM
Post #3

New D.I.C Head
*

Joined: 28 Jan, 2008
Posts: 2

QUOTE(Martyr2 @ 28 Jan, 2008 - 12:24 PM) *

You say it doesn't work, can you give us any idea why? Does it generate an error message and what is that message? Does it simply not do anything? Does it show incorrect values in the DataReport? Does it clear the DataReport results? What makes you believe it is not working?

Help us help you. Thanks! smile.gif


The error message is "Failed getting rowset from datasource...."

QUOTE(ADiecidue @ 28 Jan, 2008 - 01:52 PM) *

QUOTE(Martyr2 @ 28 Jan, 2008 - 12:24 PM) *

You say it doesn't work, can you give us any idea why? Does it generate an error message and what is that message? Does it simply not do anything? Does it show incorrect values in the DataReport? Does it clear the DataReport results? What makes you believe it is not working?

Help us help you. Thanks! smile.gif


The error message is "Failed getting rowset from datasource...."


Sorry, the error is "The parameter has no default value". Does that make any sense?
User is offlineProfile CardPM
+Quote Post

jherson
RE: Pass Varible From Form To DataReport
27 Feb, 2008 - 06:37 AM
Post #4

New D.I.C Head
*

Joined: 27 Feb, 2008
Posts: 1


My Contributions
You can do this instead

Add a variable declaration on your form
Dim qry as string
Public conn As New ADODB.Connection
Public rs As New ADODB.Recordset

Add a datasource in your form pointing on your ms access database
This should declared on Form Load
Note: Conn should be the variable used to access the datasource
for example
conn = "DRIVER={MS OLD DB 4.0 blablabla Driver};" _

On your Datareport named as DataReport1 by default
add a rptlabel and name it lbljobid

On the button of your form
Write the code

Private Sub Command1_Click()
qry = "SELECT * FROM Orders WHERE CustID = form1.text1.text "
rs.open qry, conn

Set DataReport1.DataSource = rs
If rs.RecordCount = 0 Then
MsgBox "Query found 0 Results", vbInformation, "Zero Result"
rs.Close
Exit sub
End if

DataReport1.show
With DataReport1
.Height = 10580
.Width = 13460
.Top = 100
.Left = 1700

With .Sections("Section2")
.Controls("lbljobid").Caption = rs.Fields("joborderid").Value
End With
End Sub

and lastly to close the opened rs
right click on your datareport then click view code
add this:

Private Sub DataReport_Terminate()
rs.Close
End Sub

This is just a sample of passing values "Form to Datareport"
You cannot directly connect to the form by just making a statement of form.txtjobid.text it has an explanation try and search it

Hope you get an idea...

Btw dont forget to remove from your Datareport properties the
datasource and datamember values because it will conflict with the new connection made

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 10:34AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month