Ahsan Amin


I have a combobox placed on a form that is bind wih a column of a table. I using distinct keyword for this but when i run the programe it opens the table instead of form. Here is my code

SET DELETED ON
&&SELECT a_Courses
SELECT DISTINCT a_Courses.CourseName FROM a_Courses

thisform.cboCourses.ControlSource = "a_Courses.CourseName"




Re: sql query

Alex Feldstein


In VFP if you do not supply a location for the result set it will create one by default and open it in a browse window to show the data.

Simple add a location for your temporary cursor:

SELECT DISTINCT a_Courser.Coursename FROM a_Courses INTO CURSOR MyCursor






Re: sql query

Ahsan Amin

ok, but it did not distinct the records in the combo






Re: sql query

Naomi Nosonovsky

select distinct CourseName from a_Courses into cursor curCourses

thisform.cboCourses.RowSource = 'curCourses' && this cursor

thisform.cboCourses.ControlSource = 'myTable.myField' && Should be from the table you plan to update from this combo





Re: sql query

Tamar E. Granor

After doing the SELECT, call the Requery method of the combo to refill the combobox data.

Tamar




Re: sql query

Ahsan Amin

it's giving the error when inserting the record "Cannot update the CurCursor since it's readonly"

Also table is showing no records in it that i entered yesterday





Re: sql query

Ahsan Amin

here is my code that i am using on form's Init

SET DELETED ON

select distinct a_Courses.CourseName from a_Courses into cursor CurCourses

thisform.cboCourses.RowSource = 'CurCourses' && this cursor

thisform.cboCourses.RowSourceType = 6

thisform.cboCourses.ControlSource = 'a_Courses.CourseName' && Should be from the table you plan to update from this combo

thisform.cboCourses.Requery





Re: sql query

Alex Feldstein

Ahsan Amin wrote:

it's giving the error when inserting the record "Cannot update the CurCursor since it's readonly"

Also table is showing no records in it that i entered yesterday

It shouldn't give you an error as you are not inserting (at least in the code samples you showed so far).

Make it R/W to solve this:

select distinct a_Courses.CourseName from a_Courses into cursor CurCourses READWRITE

See: http://msdn2.microsoft.com/en-us/library/tdd4h271(VS.80).aspx





Re: sql query

Naomi Nosonovsky

RowSourceType should be Alias (AFAIK, 2) and not 6 -fields. Change it and it would work.