'Program error-file in use in visual foxpro

i have to do some forms in visual fox pro 9 for a school project, and if i try to use multiple tables in one form occurs the error> file in use, even if i try to use the command "use thistable" "use secondtable" before the code, then i can not close the form at all. these are basically my codes in different command buttons but it doesn't work>

command1:

USE camera
SELECT camera.nr_camera, camera.ocupat, camera.tip_camera FROM camera WHERE camera.ocupat=.F.

command2:

USE rezervari
APPEND BLANK
replace id_rezerv WITH thisform.text1.value, id_client WITH thisform.text2.value, data_intrare WITH thisform.text3.Value, data_iesire WITH thisform.text4.value, nr_nopti WITH thisform.spinner1.value, nr_camera WITH thisform.spinner2.Value, mic_dejun WITH thisform.check1.Value

thisform.text1.Value=0

thisform.text2.Value=0

thisform.text3.Value=SPACE(20)

thisform.text4.Value=SPACE(20)

thisform.spinner1.Value=null

thisform.spinner2.Value=null

thisform.text1.SetFocus

thisform.Refresh

does anyone know what should i try? i even tried to use then close the table but it still won t work



Solution 1:[1]

command1: USE camera SELECT camera.nr_camera, camera.ocupat, camera.tip_camera FROM camera WHERE camera.ocupat=.F.

When you want to do an SQLSelect in Vfp, you would Not need to use the Use command in advance. So your code could look simply like:

SELECT camera.nr_camera, camera.ocupat, camera.tip_camera ;
    FROM camera WHERE camera.ocupat=.F.
  • And when you additionally Set Exclusive Off before you would open any table implicitly, as an SQL Select would do, then that implicitly opened "Alias" would get opened in Shared mode too. Where

SET EXCLUSIVE is scoped to the current data session

See also the F1 Help chapter on that topic.

command2: USE rezervari

When you want to open an dBase/xBase table in FoxPro programmatically, you'd normally do that in Shared mode, and inside the next unused so called work-area:

If Not Used("rezervari")
    Use rezervari In 0 Shared Again
Endif

... Where the Use Again means "even when that table is already Used() as another Alias name"

APPEND BLANK replace id_rezerv WITH thisform.text1.value, id_client WITH thisform.text2.value, data_intrare WITH thisform.text3.Value, data_iesire WITH thisform.text4.value, nr_nopti WITH thisform.spinner1.value, nr_camera WITH thisform.spinner2.Value, mic_dejun WITH thisform.check1.Value

The code you posted is a little misaligned. You could however simplify the entire Use/Append Blank/ Replace sequence with a single SQL Insert line:

Insert Into rezervari ;
    (id_rezerv, id_client, data_intrare, data_iesire) ;
Values ( ;
    thisform.text1.value, ;
    thisform.text2.value, ;
    thisform.text3.Value, ;
    thisform.text4.value) && and so on

Even easier would be to add the desired table alias to the DataEnvironment of your Form, and then add string expressions like "rezervari.id_rezerv" to the ControlSource properties of your Controls in the VFP Form Designer. That way your Form and its DataEnvironment and its Controls would do all the work for you, much less code-behind required. That's basically what the "Visual" in visual-foxpro is all about.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1