Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
I'm Missing Something - Code Review
Message
 
To
All
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
I'm Missing Something - Code Review
Miscellaneous
Thread ID:
00586950
Message ID:
00586950
Views:
49
I have a form with with 4 tabs, each tab allows the user to add information from a listbox, to a grid. Each tab represents different data. Each tab works great with the exception of the 4th. The problem is that when I add an item to the grid from the list box, it works, but it places a record in both tables instead of just one (the view is based on two tables).

I use a view called v_Questions_All to populate the selection listbox, on another form I use this same view to create the questions initially. So the view is set to update. Here is the view code from the view designer:
SELECT Coquest.questname, Coquest.questdesc, Coquest.questid;
 FROM sched!coquest;
 ORDER BY Coquest.questname
For this view, the update criteria is key (QuestID) marked to update, questname,questdesc are marked to update and send SQL Updates is check.


On the grid side I'm adding to, I use a view called v_questions_by_Proc. It is based on coprcque and coquest, and the sql code for it is below:
SELECT Coprcque.*, Coquest.questdesc, Coquest.questname;
 FROM  sched!coprcque INNER JOIN sched!coquest ;
   ON  Coprcque.questid = Coquest.questid;
 WHERE Coprcque.procid = ?gnSelProcID
The update key is coprcque.recordid and it is marked to update, coprcque.procid, coprcque.questID, coprcque.isrequired are marked to update, but coquest.questdesc and coquest.questname are NOT marked to update.

My code for adding a record from the listbox to the grid is below:
LOCAL lnCtr,lnCtr2,lcAlias,lnQuestID
lcAlias=ALIAS()
for lnCtr = 1 to thisform.pageframe1.page3.list1.ListCount
	if thisform.pageframe1.page3.list1.Selected(lnCtr)
		SELECT v_questions_all
		GOTO lnCtr
		lnQuestID=v_questions_all.questid
		lnProcID=coProc.procid
		* Check to see if this one is already in List1
		SELECT questid FROM v_Questions_by_proc WHERE questID==lnQuestID INTO CURSOR xJunk
		IF _tally > 0
			* It is already there
		ELSE
			SELECT v_questions_by_proc
			m.recordid=gnnext("COPRCQUE")
			m.procid=coProc.procid
			m.questid=lnQuestID
			m.isRequired=.f.
			m.QuestDesc=v_Questions_all.QuestDesc
			m.Questname=v_Questions_all.QuestName

			INSERT INTO v_questions_by_Proc FROM memvar
			IF CURSORGETPROP("Buffering")>1
				=TABLEUPDATE(.t.,.t.,"v_questions_by_Proc")
			ENDIF
			IF USED("coprcque")
				SELECT coprcque
				IF CURSORGETPROP("Buffering")>1
					=TABLEUPDATE(.t.,.t.,'coprcque')
				ENDIF
			ENDIF
			SELECT v_questions_by_proc
			=REQUERY("v_Questions_by_Proc")
			this.parent.Refresh()
		ENDIF
	endif
endfor
thisform.Refresh()
SELECT coProc
The problem is that it inserts a record into the coprcque table like it is supposed to, but it also inserts a record into the coquest table (not supposed to).

Any help greatly appreciated.
Next
Reply
Map
View

Click here to load this message in the networking platform