PDA

Click to See Complete Forum and Search --> : DBGrid Dillema


Rob Brown
May 8th, 2000, 06:57 PM
Hi,

I'm using a DBGrid Control to represent information from a database and want to give the user a facility to filter the records.

The data control that the DBGrid uses as a datasource has a RecordSetTypeProperty of 0 (table).

I am using a combo box for the user to select a field to filter by and a text box for them to enter a value for that field.

The user then clicks on a command button in order to filter the records using the following SELECT statement:

dtaEditDatabase.RecordSource = "SELECT * FROM tblMain WHERE " & cboFilter.Text & " = '" & txtValue.Text & "';"

This does not produce an error (ie: Syntax error in SELECT statement)

However, my DBGrid control still displays all the records in the table.

How do I get it to show only the records from the new recordsource?

Any suggestions would be greatly appreciated.

Best Regards,

Rob Brown.

Rohan_Powle
May 8th, 2000, 07:31 PM
According to what u wrote u want to display the records in the dbgrid which r matching the critiria of the combo box..if yes try this...

The combo box will contain the Code's list...
data1 has the recordset which ur displaying in the grid...
try this code
--------------------------
combo1_click()
data1.recordsourse = "select * from <table> where code='" & combo1.text & "'"
data1.refresh
--------------------------
this code will change the recordset in the memory..
& refresh will show the new recordset in the grid
tell me if u r having problems

Rob Brown
May 8th, 2000, 08:20 PM
I have tried this using the refresh method and am now getting the following error:

I selected Site from the combo box (one of the fields in my table). This box is called cboFilter

I then placed the value Kinnegar into my text box (txtValue). There is more than one instance of this in the database.

My table is called tblMain.

I am using the following line of code:

dtaEditDatabase.RecordSource = "SELECT * From tblMain WHERE " & cboFilter.Text & " = " & Chr(34) & txtValue.Text & Chr(34) & ";"

VB returns the following error:

The Microsoft Jet database engine could not find the object 'SELECT * From tblMain WHERE Site = "Kinnegar";'. Make sure the object exists and that you spell its name and the path name correctly.

VB doesn't even appear to be recognising this as a select statement (otherwise it would usually return the error "Syntax error in SELECT Statement").

Any ideas?

Rohan_Powle
May 9th, 2000, 02:03 PM
dear friend,
ur way of giving the Select Statement is wrong....
if i am not mistaken dtaEditDatabase is a datacontrol ...then here is the solution....
give this select statement...
---------------------
dtaEditDatabase.RecordSource = "SELECT * From tblMain WHERE " & cboFilter.Text & " ='" & txtValue.Text & "'"
dtaEditDatabase.refresh
---------------------
-- Best OF Luck Rohan :-)