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!

VFP Form combo error

Status
Not open for further replies.

eric43

Programmer
Apr 29, 2005
94
0
0
AU
I have a form with three combo boxes.

Each one's contents is based on a selection in the previous. After the second I am trying to apply a filter ie applies a filter via a SELECT sql.

Now when I get to the third combo I get an error 'Cannot access the selected table'.

I find I need the underlying tables/arrays/cursors to be in scope when I open the form so I USE and recreate the table/array/cursor based on the previous selection.


Anyone have any clues as to what is happening.

It makes no difference whether I USE and SELECT after the SQL or not - or use a table/array/cursor - when I select the combo I get the error.

Anyone point me in the right direction? - this is a critical form in my app - to make selection of a person based on a criteria instead of from a long list of names.

Thanks

Eric
 
There are so many ways of doing this that it's difficult to know what might be going wrong. How and when are you populating the third cursor? For example, are you generating an array in the LostFocus or in the InteractiveChange of the previous combo, are you creating a cursor in the GotFocus of the third combo, are you using a filtered table in some way?

Geoff Franklin
 
Geoff,

Im using the Interactive Change and using a SELECT SQL statement to create a new table - as I said I've tried cursors and arrays.

As a matter of interest I have removed the 3rd combo from the form and created a small form with a combo based on the new table which I bring up after the SQL and that comes up poulated correctly. I know this is a klug but maybe that's what it will have to be.

Regards

Eric
 
Ever when working with combos (and grids) that change its content interactively issue a Recordsource command BEFORE recreating the cursor that populates the combo/grid.

Code:
Thisform.combo1.recordsource=""

<SQL Statement> into cursor mycursor


Thisform.combo1.recordsource="mycursor"
Note that the quotation marks are without spaces between them. This is specially neccesary with grids to avoid reconstruction.
 
I wouldn't recommend using tables for this. I find the easiest ways are to arrays or cursors. In each case, put the code that creates the array or cursor in the Requery method of the combo. Call the Requery method from the Init method.

In the InteractiveChange of one combo, call the Requery method of the combo that it controls.

Tamar
 
I'd agree with Tamar on not using a table as a RowSource but you have to be careful with arrays. If the SQL finds no matching records then it won't create the array and your form will crash. SQL can easily create an empty cursor or an empty table but you can't have an empty array.

You need some code like this:

Code:
 IF _TALLY  = 0
   *-- The array will not have been created
   *-- Create a single-element array and put a ' ' in it
   DIMENSION laCust[1]
   laCust[1] = SPACE (1)
ENDIF

Geoff Franklin
 
Hi Guys,

Thanks for the suggestions above.

I have decided to use the 'new form' method I mentioned above s this is working seamlessly.

Many thanks

Eric
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top