Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command object and Data grid

Status
Not open for further replies.

treecody

Programmer
Jul 25, 2001
16
0
0
US
Hi,

I'm new to VB. I need to know how to get data into a data grid. I have a form where the user enters a range of dates. I'm using an SQL statement to find the records. How do I set the datamember to a new command. I need to do this at run time not design time.

the code I have is as follows:

Dim WithEvents cnhbook As Connection
Dim rshbook As Recordset
Dim cmd1 As Command
Private Sub cmdrsrch_Click()

Set cnhbook = New Connection
Set rshbook = New Recordset
Set cmd1 = New Command


With cnhbook
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "data source = d:\theresa\hist\books.mdb"
.Open
End With


Set cmd1.ActiveConnection = cnhbook
cmd1.CommandText = &quot;select * from books where cdate(bdate)>='&quot; & txtstdt & &quot;' and cdate(bdate)<='&quot; & txtenddt & &quot;'&quot;
cmd1.CommandType = adCmdText
Set rshbook = cmd1.Execute

now what do I do?????

Any help would be apprecitated!!

Thanks.. Theresa

 
Add an ADO Data control to your form (we'll call it adoData). Select the ADO Data control as the data source for your grid. Build your SQL Statement based on the dates entered and then update the recordsource for the Data control.

Dim sSQL as String

sSQL = &quot;select * from books where books.DateField >=#&quot; & Me.txtFromDate & &quot;# and Books.DateField <= #&quot; & Me.txtToDate & &quot;#&quot;

Me.adoData.RecordSource = sSQL
Me.adoData.Refresh

 
Hi Terpfan2001,

Thanks for the input, but I get the error it is read only. I really don't want to have a data control on the form. Is there way to just name the command object so I can set the datagrid.datamember to the name of the command?

Theresa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top