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

Dataenvironment with 2 forms and code.prg

Status
Not open for further replies.

metron9

Programmer
Mar 5, 2002
94
US
I have 2 forms both forms have seperate tables in there dataenvironment.

Form 1 DE has mainfile.dbf
Form 2 DE has srchwrd.dbf

Form 1 has a SEARCH button control that calls Form2

When Form 1 gets focus again the mainfile is open but the workarea has changed and the program asks for a .DBF file. If I select a mainfile.dbf it says file is open.
The thing is, It was working before just fine. I even made a new form and put a .dbf file in its DE. that it calls for a test and that form does nothing at all but return to form 1 with thisform.release in the click controls event.

I solved the problem with using "select mainfile" in the GOTFOCUS method of form1 but why is the work area changing. Why did it work fine before tonight. Is this ok to put select mainfile in the Gotfocus event.
 
Sounds like you need to set the datasession to private in both dataenvironments.

It makes these types of issues simply go away.

There are times when you'd want to set the datasession of a called form to the same datasession as the calling form, but this I believe, is not one of them.


Hope helps,

Darrell 'We all must do the hard bits so when we get bit we know where to bite' :)
 
If I set them private can i still use
use mytable in 0 again alias mytableagain
I have a function that sets a logical field in the file when the file matches a search parameter.
 
Yes, although you'll have to watch how you handle buffering.

By the way, what are you trying to accomplish?

Darrell 'We all must do the hard bits so when we get bit we know where to bite' :)
 
metron9

If I set them private can i still use
use mytable in 0 again alias mytableagain


Yes, you can. But I would use:
USE myTable shared again in 0
The is no need for the alias.

If your forms have private datasessions, couldn't you just put the tables in the dataenvironment of the form? It comes out to the same as using:
USE myTable shared again in 0
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
<<<What is it you are trying to accomplish?>>

The code is in a program file below is the code.

in a nutshell I have a list of words in a table and a list of words the user has just input to search for. I seacrh thru the table of words one at a time when a word matches
I have a pointerfile that points to a words record and to the record in the main file that has that word. When I find the record number in the pointerfile i select the mainfile and goto that record. I then replace a logical field with a .t. for that record. When I return to the form i use set filter to srchfound = .t. Now the user can click thru records that match his list of words.

It works perfectly good.

FUNCTION SRCHSET

nSelect=select()
USE pointfile in 0 order wrdpointer alias apoint
USE srchlst in 0 alias asrchlst
USE wordlist in 0 order srchword alias wlist
USE mainfile again IN 0 ALIAS mainfileAgain

* Reset all records to .F.
SELECT MAINFILEAGAIN
GO bottom
mflast=recno()
SET ORDER TO SCHFOUND
GO TOP
DO WHILE SCHFOUND
REPLACE SCHFOUND WITH .F.
SKIP
ENDDO

SELECT asrchlst
GO top
DO while .not. eof()
* find the users search word in the words list
SELECT wlist
SEEK asrchlst.slword
IF .not. eof()
recid=recno()
SELECT apoint
SEEK recid
IF .not. eof()
* find and mark all of the files that contain
* that search word
DO while .not. eof() .AND. WRDPOINTER = RECID
recptr=recpointer
IF mflast>=recptr
GO recptr in mainfileAgain
REPLACE mainfileAgain.schfound with .t. ENDIF
Skip
ENDDO
ENDIF
ENDIF
SELECT asrchlst
SKIP
ENDDO
* close files
USE IN WLIST
USE in mainfileAgain
USE in apoint
USE in asrchlst
SELECT(nSelect)
ENDFUNC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top