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

Using 1 table in 2 different forms

Filip Brnic

Programmer
Dec 25, 2023
51
RS
Hello, i have an issue

First of all let me just give you a picture of the form layout

FORM 1
Tables: Robak, Roba
Has a grid connected to robak
A button that opens a form that needs to load Robak

FORM 2
Tables: Robak

So i tried the following

In form 1 command button
do form form2

in form 2 init property i have the following
use robak shared
select robak
(some code that works below not connected to this)
i also have data session set to 2 in this form

When i try to use the button in form 1, with data session set to 2 in form 2 i get the error this file is used by another user
When i try to use the button in form 1, with data session set to 1 in form 2 i sucessfully open the form2 but the issue now is that my grid just becomes blank, dissapears. I'm currently reading the help guidance provided by fox, i stumbled upon set releation to procedure, but im still trying to figure out what to do.

And to mention i don't have anything in the data enviroment in form 2 just incase anyone was wondering because i know that can mess things up sometimes.
 
"File is used by another user" sounds to me like you have used a file exclusively, or you used an FLOCK() to lock the whole file.

So, before looking into the data session issues, check to be sure you have SET EXCLUSIVE OFF and that you haven't opened any tables with EXCLUSIVE or called an FLOCK() somewhere, which lock the entire file.
 
Nope, no flock and set exclusive is off in both forms load property...
Then the problem is related to the data sessions.

I never use data sessions, so I don't have any experience troubleshooting them, but I know enough to know that there are configuration options in data sessions that you can explore such as private vs default datasets (private isolates the session and keeps record positions, index orders, etc. independent from the default), and there are multiple buffering options that may play a role.

Since you said one form has a data session, and the other does not, this should be the first thing you explore.
 
the issue now is that my grid just becomes blank,

This is a separate issue - not related to the error you are seeing or your DataSession settings.

The problem occurs when you set the grid's RecordSource, but then later close the underlying table (the one that the RecordSource point to), and then re-open the table. I don't know the exact sequence of events in your case, but I suspect it is something along those lines.

The solution is to remove the RecordSource (that is, set it to an empty string), then re-open the table, then set the RecordSource back to pointing to the table.

Also, I don't think SET RELATION will help in this case. Whatever caused the "File in use by another" error won't be solved by SET RELATION.

Mike
 
Hi,

The DATASESSION property of each form has to be set to 2 (Private). Then you have full control of the underlying table(s).

From Hacker's Guide to VFP 7

Set an object's DataSession to 2 to keep it private. This allows multiple instances of the same object to be running at the same time without interfering with each other. Each form has its own DataSessionID, its own set of work areas, its own record pointers and its own set of aliases. This last is really cool. With a private data session, you can use the same alias every time, something you can't do with USE AGAIN.

You may also want to have a look at "Programming for Shared Access" in the help file.
hth

MarK
 
Just open the DBF like
Code:
MyGRID.addproperty("SrcAlias", "D_"+ThisForm.name)
USE (sourcefilename) alias (MyGRID.SrcAlias) in select(MyGRID.SrcAlias) SHARED [NOUPDATE] AGAIN
MyGRID.RecordSource = MyGRID.SrcAlias
in both forms.
Here You have 2 different Aliases
 

Part and Inventory Search

Sponsor

Back
Top