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!

how to append to views which are related?

Status
Not open for further replies.

Nifrabar

Programmer
Mar 16, 2003
1,343
NL
Hi!
I do have an a form multiple updatable, buffered views.
View1 is the 'master' view.
This one will skip through the records.
A second view is parametrized based upon an other table. Parameter is the id of view 1.

Q:
I can append a record to both views, but how do I know newID of view1?
That numeric must be stored in view2 to keep them tight.

Any idea?
-Bart
 
What is your VFP version and what do you use for primary key? NextID() routine or AutoIncrement? If the later, you may be out of lack...
 
Ilyad,
It's VFP9 and primairy key is an autoinc.
-Bart
 
I see. I was afraid of that. You're in a dead-end situation and I was in the same exact situation too :( With Autoincrement field you can not get a new ID until you do tableupdate, which you obviously can not do. I think, there is no solution to this problem, except for actually saving the parent before proceeding with the child. AutoInc fields look like a great way to use for PK, but they have this big limitation, which make them almost useless for the situations you describe :(
 
Ilyad,
I do plan to solve this way:
begin transaction

begin transaction

tableupdate main view

if tableupdate is ok
end transaction
otherwise rollback

take prim.key of main view and put into secundairy views
tableupdate sec. views

ask for confirmation
resulting in
either rollback
or
end transaction

-Bart
 
Yes, I was thinking along these lines too.

E.g.
Code:
llCommit = .t.
BEGIN TRANSACTION
if tableupdate(.t.,.t.,'MyMainView')
  lnNextID = getautoinc()
  replace fk with lnNextID in MyChildView
  if not tableupdate(.t.,.t.,'myChildView')
      llCommit = .f.
      =aerror(laAerror)      
  endif
else
   llCommit = .f.
   =aerror(laError)
endif

if m.llCommit 
   END TRANSACTION
else
   ROLLBACK
   tablerevert(.t.,'myMainView')
   tablerevert(.t.,'myChildView')
endif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top