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

GetFldState not working consistently 1

Status
Not open for further replies.

mkrausnick

Programmer
Apr 2, 2002
766
US
I have client company table and a separate client contact table.

The contact data entry form has:
1. A listbox showing all companies
2. A second listbox showing all contacts for one company
3. All the contact information textbox fields for the contact, bound to the contacts table fields.
4. Buttons: NEW, SAVE, CLOSE.

The user first clicks the company in the company listbox, which sets a filter on the contacts table, causing the second listbox to display contacts for only that company. Then the user clicks the contact to be modified in the second listbox and the data for that contact may be modified in the data entry section.

Buffering for the contacts table is set to '3'-Optimistic Row.

I have the following "CHECKMODIFIED" function that is called from <companylistbox.click>, CLOSE, and the form's QUERYUNLOAD event:
Code:
LOCAL lModified, nResult, nFieldNum
lModified = .F.
SELECT provcont 
FOR nFieldNum = 1 TO FCOUNT("provcont")     			&& Go through fields, checking for any field that's been modified.     
   IF GETFLDSTATE(nFieldNum,"provcont") = 2      
      lModified = .T.
      EXIT
   ENDIF
ENDFOR 
IF lModified
	nResult = MESSAGEBOX;
		("Information for the current contact has been modified.  Save these changes?", ; 
		3+32+512, "Save Changes") 
     DO CASE 
     	CASE nResult = 7      		&& Save=No            
			TABLEREVERT (.F.) 
			RETURN 0
		CASE nResult = 6			&& Save=Yes
			TABLEUPDATE(0,.T.,"provcont")
			RETURN 0
		OTHERWISE 
			RETURN -1				&& Return to form 
   ENDCASE 
ENDIF 
RETURN 0

Now, if the user modifies a field and then closes the form by either the CLOSE button or clicking the "X", GETFLDSTATE correctly returns '2' for the modified field, and the messagebox is displayed.

But if the user modifies a field and then clicks a different company, although the CHECKMODIFIED function is called, GETFLDSTATE returns '1' for all fields including the one that was modified.

The call structure is the same in all three places:
Code:
IF Thisform.Checkmodified() < 0				&& Returns -1 if user clicks CANCEL
	NODEFAULT 
ELSE 
.
. Do some other stuff
.
ENDIF
This has me stumped. Why doesn't GETFLDSTATE always return '2' if a field is changed?

Mike Krausnick
Dublin, California
 

Mike,

The answer is simple: You are using row buffering.

You said that the problem occurs when the user clicks through to a different company, in other words, when they move the record pointer. Remember, with row buffering, moving the record pointer causes an implicit table update.

So, by the time you get round to checking GetFldState, the record has been committed and therefore no longer shows as being modified. In fact, GetFldState is operating on the new current record, which has not yet been modified.

My advice would be: if you use row buffering, do not allow the user to move the record pointer until the record has been either committed or reverted.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
My advice would be: if you use row buffering, do not allow the user to move the record pointer until the record has been either committed or reverted.

Right - that's exactly what I'm trying to do. If the user tries to change the company, I want to stop her if changes were made to the current contact and not saved. That's why the first thing in the click event of the company listbox is a call to CHECKMODIFIED, which calls GETFLDSTATE for the contact table. If no changes, then it resets the contact table's filter to populate the new company's contacts.

I stepped through the CHECKMODIFED function - and the CONTACT record pointer is not changed when the user clicks on the company listbox to select a different company - it's still sitting on the record that was modified, but it returns '1' - no change, for the field that was modified. I even explicitly identified the contact table alias in the GETFLDSTATE call - didn't help.


You seem to be saying that changing the record pointer in one table causes a record in a different table to get committed. That doesn't make sense.

Maybe I should post the whole form. How do I convert the form into code so I can paste it here?

Mike Krausnick
Dublin, California
 

Mike,

<< You seem to be saying that changing the record pointer in one table causes a record in a different table to get committed. >>

I agree that would not normally be the case. But aren't you re-setting the contact table filter when the user selects a different company? Could that be causing record navigation in the contacts table? Come to think of it, that doesn't sound likely.

What I originally had in mind was that you would make the editable fields initially read-only. When the user reaches the contact in question, she clicks on an Edit button. This makes the fields read-write, and also disables the two listboxes. In your Save button, you reverse that process. You would also need a Revert button, to let her cancel her edits.

I'm not now sure if that would solve the problem or not (but is should at least avoid it). (Sorry, it's after 11 pm here, and my brain is at its fuzziest.)


Maybe I should post the whole form. How do I convert the form into code so I can paste it here?

OK, I can handle that question.

Open the form in the VFP class browser (Tools menu). Click on the View Source Code button. That will open the code in a window, which you can either save to a file or copy and paste.

However, could I ask that, before posting the code, you strip out everything that's not related to the problem (Top = 15 or whatever). That will make it easier to focus on the issue.

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Thanks for the quick reply. I was thinking along the same lines you suggested about enabling/disabling the listboxes. I'll re-engineer the form and see if the problem goes away.

I hope you went to bed and you see this tomorrow. If not, go to bed now. Or at least turn off the computer! :)

Mike Krausnick
Dublin, California
 
I was able to enhance the form to better control the user's actions. I use an EDIT button plus an UNDO button and totally control what is enabled while editing and while not editing. The problem no longer occurs.

Mike, you deserve a star just for staying up so late! and also for the solid advice.

Mike Krausnick
Dublin, California
 

Mike,

I'm glad you've got it working, and thanks for the star, although I have to admit I didn't stay up late specifically to work on your problem (I'm not that dedicated <g>.)

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top