PDA

Click to See Complete Forum and Search --> : Using the Data Environment...


FLL
Jul 10th, 2000, 09:58 PM
Hello, all. I have posted a question or two in here before concerning a program that I am writing (as I teach myself VB6 Database programming). I have learned how to use ado and have it do what I want it to, but when I try to use the data environment, I am running into some problems. I am manipulating the commands in code instead of entering them in when the data environment is created. When the form loads, I have the code that sets the command text:
DataEnvironment1.Commands("Command1").CommandText
= "Select * From Customers" (The text is on
one line here)

For the click event for a command button I have:
DataEnvironment1.Command1 (to execute command)

Then there is the code to set the properties of the text boxes to display the query results.

I think the fundamental problem is a misunderstanding of how the recordset object works within the Dataenvironment.

Could someone please give me some direction here, preferably by a coding example of what to do when one has a dataenvironment, wants to set the command text in code, wants to use a command button to execute this command, and have the recordset returned to a few text boxes on the form? The small amount of coding I provided above omitted setting the recordset object, because I am lacking understanding of how that worked. Thanks a lot!

FLL

CGTS
Jul 11th, 2000, 01:38 AM
I'm not sure this is what you are after, but lets give it a go.....

If you have created your commands in the data environment, you it will probobly have set the 'Recordset Returning' option on the advanced properties tab. If this is the case then you can code the source of this recordset and use a DataBinding collection to bind the results to your Text boxes.

Assume you have a command called cmdTest, you will end up with a recordset called rscmdTest.
------------------------------------------------------------

Dim bnd As BindingCollection

Private Sub Form_Load()
Set bnd = New BindingCollection
With bnd
.Add Text1, "Text", "Field1"
.Add Text2, "Text", "Field2"
'.Add Text2, "Text", "Field3" Etc. Etc
.DataMember = "cmdequip"
Set .DataSource = DataEnvironment1
End With
End Sub

Private Sub Command1_Click()
With DataEnvironment1
' By default the recordset object is Closed, however you need to ensure it is closed before re-opening
If .rscmdEquip.State = adStateClosed Then .Close
.rscmdTest.Open "SELECT * FROM tblTest WHERE txtField = 'TestInfo'", DataEnvironment1.Connection1
End With
bnd.DataMember = "cmdTest"
End Sub

------------------------------------------------------------

I have to admit I have tried your way of changing a command text and although it appears to change the text, it doesn't appear to do alter the data.

Why wouldn't you just use straight ADO code ?

FLL
Jul 11th, 2000, 07:39 AM
I want to use the data environment because of its compatibility to the report designer, and I do want to use straight ADO coding within the project, so I set up the dataenvironment, set the commands to text commands using sql, try to execute the command on a click event with:

DataEnvironment1.Command1
Text2.DataSource = rsCommand1
Text2.DataField = "ContactName"

But I keep getting an error message that says that VB is unable to bind Text2.DataSource or it tells me that Text2.DataSource is not a valid command. This is what I am failing to understand.

It seems simple enough, and I get it to work properly with just an ADO object, but when I use a data environment, it won't bind. I am guessing I am leaving out something important concerning the recordset object?

Is there some reason you can see why this wouldn't bind? I have taken a look at your code and will try it when I get home from work...thanks a lot! Any guidance concerning programming within the data environment would be greatly appreciated.

FLL