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

Newbie problem with VFP forms and databases

Status
Not open for further replies.

JCoates

IS-IT--Management
Dec 13, 2001
19
US
Hello all;

I've got quite a bit of 2.6 experience, but am fairly new to setting things up in Vfox6... I am trying to open databases in a startup program (startup.prg if you will)... and then use these databases to display fields within my forms (also called from startup.prg)... however, it seems that unless I manually go into the form builder and setup the data environment for each form, the databases I have opened in my startup.prg are not shown as open.

I'm hoping to open the files as part of the startup procedure and then use them from that point on until the startup program closes them.

What am I missing?

Thanks,
Jim Coates
jcoates@westmusic.com
Director of IT
West Music Company
 
If you wish to use the tables you already have open, make sure your form's DataSession property is set to "1-Default Data Session"

Ian
 
chpicker,

I do indeed have it set to the default data session... but I still cannot call the alias names unless I go in and add them to the actual forms data environment.

For example... in the startup I am calling:

use materials.dbf alias material in 0 shared

then within the form I do some calculations based on some of the database fields:

if material.name = "test"
etc...

But when the program runs, the form errors out and says that alias material cannot be found.

If I add it to the data environment manually, then rerun.. it works.

Jim

 
Hmm...that's very odd. I do this all the time with forms that ask for information from the user.

Try placing this code in the form's INIT event:
[tt]
MessageBox("I am using data session "+;
alltrim(str(thisform.DataSessionID)))
[/tt]
See which number comes up.

Can you post your startup PRG file up to the point where you call the form?

Ian
 
chpicker,

Right now the startup is very simple...

"close data

use data\master alias master in 0 shared

use data\materials alias material in 0 shared

do form startup"

I should add that my "startup" form DOES call another form and that is the form I am getting the errors on, but I made sure that my data environment in the first form is set to not autoclosetables.

Yet, when I get to my second form, I get:

if not empty(master.warranty)
Error: 13
Alias 'MASTER' is not found.
Method: warranty.refresh
Line: 1

Jim
 
Make sure that BOTH forms are set to Default Data Session. If either one is set to Private Data Session you'll get this error for sure.

For clarity, try adding this just before the DO FORM in your startup PRG:
[tt]
IF !USED("master")
MessageBox("Error opening Master table")
ENDIF
IF !USED("material")
MessageBox("Error opening Materials table")
ENDIF
[/tt]
See if either of these boxes pop up. Then add similar lines to the INIT() method in each of your forms.

Ian
 
chpicker,

Nevermind... I found my issue.

I went to add you code to the ORIGINAL form to see what data set it was using... and low and behold when I opened the "init" method, I found a "close data" in it.

Opps...

Jim
 
I do still have one issue though...

Now when I get to my second form, none of my data is showing up...

And when I try to exit, I get:

=CursorSetProp("buffering,THIS.oldBuffering,aTablesUsed[m.i,1]) &&optimistic table buffering
Error: 1545
Table buffer for alias 'master' contains uncommited changes.
Method: destroy
Line: 68
 
Hmm...somewhere your form is making changes to the Master table. At what point before this do you set the buffering? At form load? What do you set it to?

Ian
 
chpicker,

I actually haven't set any buffering manually... I created the main form using the form wizard... so the buffering and such must be setup as a part of the button row that the wizard adds to the form.

The purpose of the form IS to make changes to the master database, but even if I don't input anything (IE - just browse the form and click exit) I still get the same error message.

Jim
 
Perhaps you should just take that line out, then. If you created the form using the Wizard, then the Wizard class is already taking care of this for you.

Ian
 
chpicker,

Sorry I'm not following you...

Which line should I take out? I didn't add anything that its showing errors on, that's all from the wizard.

Jim
 
Hmm...

Did you use the Wizard to create both forms? Do both forms use the same tables?

Chances are what is happening is that the first form sets buffering...changes get made...the second form is called...when the second form exits, it diligently tries to "put back" the buffering to what it was before it was called, and VFP doesn't like that because changes had been made to the table.

I've personally found using the Wizards to be problematic. It's VERY difficult to debug a form when you don't know most of the code behind it.

Can you describe the purpose of each form and what causes each to be called?

Ian
 
Ian,

ok... here's the order of the program...

setup.prg calls the form "setup".

Setup (form) contains three buttons, one to exit, one to edit and one to browse (each calls a different routine or form). It was manually created using the form editor and is set to the default data set, but does not edit or display any data variables.

Master (form) is called to do editing. This form was created using the form wizard and has their standard buttons for top, prev, next, bottom etc attached to it. It also uses the default data set and DOES have the capability to edit the data using the wizard buttons.

Setup is still open in the background when Master is opened.

Jim
 
Hmm...

With the setup you have, it might be a good idea to set your Master form as MODAL (WindowMode=1). See if that fixes your problem.

If you set this, however, you will not be able to open ANY other forms until the Master form is closed.

Ian
 
In order to do that I can't have this as a top level form though correct?

Could I close the form as part of a "click" method? Would that achieve the same result?

Sorry to be such a newbie on this... but it acts very differently than the 2.6 world I'm used to.

Thanks,
Jim
 
I'm honestly at a loss. I've never used 2.6. I only just started using Fox less than 2 years ago, and I started with version 6.0. As I mentioned before...Wizard forms are a PAIN. If you must use them, you should let them stand alone.

Are you saying that you want the Master form to be a Top-Level Form? Or is it the Setup form that is Top-Level and the Master Form is set to be In Top Level Form? If it's the second one, then you can still set Master to Modal. If Master is Top-Level, you cannot set it Modal...and I highly recommend using a Private Data Session.

Ian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top