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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

close a single table stored in a variable

Status
Not open for further replies.

thegame8311

Technical User
Jan 6, 2012
133
US
I have done the methods found on here but they don't seem to work:

Code:
select (Team_name)

use

Code:
use in (Team_name)

not sure where to go next because Team_name is variable that contains the name of a table, which I know is unorthodox but it is what I am doing.

each time is know the name of the table but thinks that I am using it as an alias, but all i am trying to do is close the previously used table because upon re-entering the form it will not be the same table selected
 
What I would do is more like this:

Working on the assumption that Team_Name is a string var:
Code:
Team_Name="MyTable"

Then

Code:
if used(Team_Name)
  select(Team_Name)
  use
endif

Works for me

Note no space between the SELECT and (Team_Name)


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
ok not for some reason I am getting 'field phase not found'

I ran it through the debugger and it know the variable name so not sure what the deal is. Here's the code that is in the form's init that seems to be cause the problem

the arrow is referring to the line that it errors on, it's not actually part of the code

Code:
Parameters Team_name

if used(Team_Name)
  select(Team_Name)
  use
endif



SET EXCLUSIVE OFF

if empty(Team_name)
  return .f.
endif 
if not used(Team_name)
  USE (Team_name) IN 0
endif 
this.AddProperty("curTeamName",Team_Name)

lcCurTeamName = thisform.curTeamName

thisform.list1.RowSourceType = 2
->thisform.list1.RowSource = (lcCurTeamName)
thisform.list1.Listindex = 0 
thisform.list1.ColumnCount = 4
thisform.list1.ColumnWidths = "0, 50, 150,150
 
I don't think you need to put the reference to lcCurTeamName in brackets.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
well i don't but did removing the parens did not fix the issue
 
Works fine either way (with or without parenthesis) for me.

Is the table in question called Team_Name or does it have a field called Team_Name?

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Why the bloody hell did you ask about closing a table when the error is on assigning a Rowsource? It has nothing to do with closing a table and is a complete waste of time.

The help file for Rowsource has this note:

When you set the RowSource property using code, you must enclose the value with quotation marks ("").

But since I have little faith that your problem has anything to do with Rowsource either, all bets are off.
 
Dan, I don't think his code got as far as the error without closing the table first.

Mind your language, please

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Code:
USE IN (Team_Name)

But that will fail when the table isn't open, so either of the following should work:

Code:
USE IN SELECT(Team_Name)

Code:
USE IN (SELECT(Team_Name))

Tamar
 
OK, ignoring the error message that cannot come from closing a table, and ignoring the code showing an error coming from setting controlsource:

What makes you think the table was not closed? What is the symptom you are trying to diagnose?
 
Not reading all that has been said it seems you still don't now the reason of the error "field phrase not found".

A field phrase is the list of fields you can set in a controlsource. So I guess the error does come from closing the table, it's just indiretly: You show the records of this table in some listbox, combobox or something like that and when closing the table, that control is throwing that error.

You rather let the release and unload of the form close tables, its automatic, if the form has a private datasession anyway and you don't do anything.

Bye, Olaf.
 
* What is the error you're getting?
* Why the bloody hell did you ask about closing a table when the error is on assigning a Rowsource? It has nothing to do with closing a table and is a complete waste of time.
* I don't think his code got as far as the error without closing the table first.
* What makes you think the table was not closed?

Based on the usual level of confusion that surrounds most of your questions (as can be seen in the subsequent requests for clarification from the responders) have you used the SET STEP ON to ACTUALLY "SEE" REALLY what is going on in your code?

If you had done so you should have been able to CLEARLY define the challenge you face instead of just asking in a TOTALLY UNCLEAR MANNER and not promptly responding with clarifications - thereby causing all of us to have to repeatedly GUESS how to help you.

Good Luck,
JRB-Bldr


 
To make my point clearer:

You are closing a table that is still used by some control as it's controlsource/rowsource/reordsource, most probably a rowsource with rowsourcetype=6 (=fields).

There is no line of code throwing that error, but it's thrown due to closeing the table. So simply don't. It won't hurt to keep a table open until the form closes. We're far from the age, file handles were a valuable resource.

If you want to be very tidy, then first unbind controls using the tables, before closing tables.

Bye, Olaf.
 
ah, now I begin to get it.

thegame8311, do you have the listbox already bound to a data source before you try and assign it to your Tean_Name?

If so, remove that lick at design time (interactively, just blank it).

Then it should be ok.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Griff,

I don't know, but you have a point there, thegame didn't tell when closing the table. I assume we talk about the release of a form, or changing to another team table, perhaps.

At the start of a form you open tables and keep them open, normally, don't ou, Griff?

Bye, Olaf.
 
Hi Olaf,

No, thegame8311 was not very clear - sometimes that's half the fun here, sometimes it makes the exp. less than fun.

As for your question, I guess it depends, most of the time I design a form with a specific table(s) in mind and yes, I expect the table to be open(ed) at the init stage and usually closed on the release... but there are exceptions - the main one (which is common across a number of apps) is the form that selects which project, workshop or whatever I am about to work in.

I have a grid on that, which is not bound to anything at design time and I tend to select the table to fill it at run time - it's just a list of databases, with descriptions and paths. Then I use the INIT to set the columns, control soure etc. programmatically.

Horses for courses


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Well,

changing from one to another table is a reason, yes. If doing so, you first unbind control(s), open other data and bind controls to it.

I can imagine thegame to do that, another reason to rather put teams into one table and index on a teamid and change between teams via SET KEY TO instead of scattering players across several tables.

@thegame: Again an overall observation: You think the PHP way, which is to query data into arrays you then loop to create html snippets.

On thing is different in VFP: You don't fetch data into arrays (you could, but it makes no sense) you either USE a table or sql-select into cursor and both times use them as source of the form controls directly.

One thing is different in Winforms: You don't create HTLM code sent to a browser and rendered there, you visually create forms and they stay in memory and are stateful, and that#s not only ok, it's an advantage.

You reprogram too close to your original code.

Bye, Olaf.
 
*Just Curious, but are you trying to do this with paths to your tables?

team_name = "C:/appl/data/immune"

*IF so, you can simply, cut the last part, used expects just the alias name

tbl_alias = JUSTSTEM(team_name)

IF !used(tbl_alias)
USE &Team_name IN 0
ELSE
WAIT WINDOW "Talble is Already Open"
endif

SELECT &tbl_alias && Open Table
BROWSE

USE IN &tbl_alias && Close Tbl
 
It's a bad idea to use macros in the USE command. Name expressions work, are (slightly) faster, and mean you don't have to worry about whether the path is included and has spaces:

NOT:

USE &Team_name IN 0

But:

USE (Team_name) IN 0

Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top