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!

File not being updated correctly

Status
Not open for further replies.

mpgalvin

Programmer
Feb 5, 2001
119
IE
I have a grid (yes, it's the same grid as the other problems I've been having lately. I don't know why I'm having so many with this one grid).

I've got 3 fields in the table, 2 of them are shown in the grid. Field A is a system total. Field B is the user total. Field C is the difference between A and B.

The theory is that Field A is filled by the system, then the user comes along and fills in Field B using the grid. Then I want to fill in Field C with A-B. I'm doing this in the keypress event of the grid.column.text control.

However, it doesn't work. With some corollary:

1. It does update the record, just puts 0 into Field C no matter what A-B actually is.
2. If I step through the keypress event, it works fine.
3. If I re-do the record (ie., enter something else in Field B), it works fine with *that* detail, but loses whatever I did first time around.

These are all very strange occurences. My boss though moving everything to beforerowupdate event might help, but I can't see what would cause all of the above.
 
mpgalvin

Try your calculation in the .InterActiveChange event of the textbox.

Alternatively you need to capture the value of nKeyCode and use it your calculation in the .KeyPress event.

Off topic, but it would be helpful if you could advise the outcome of your other threads concerning grids?

Chris :)
 
I assume that field C is a calculated result field.
Using the KeyPressEvent is wrong. YOu can use the interactive event Chris mentioned. But my suggestion is...

FiledC.ControlSource = Fielda-fieldB

In the lostfocus event of fieldB, do a refresh of fieldC (FieldC refresh) or a refresh of the grid. i.e. ThisGrid.Refresh()

Best of luck with the grids ! :)

ramani :)
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
 
Thanks to both for the help. I basically ignored your good advice :) and added a REPLACE... WITH command to my code section so that what was being typed into the grid (and therefore I assumed being written to the file) is actually explicitly written. And it works!

Not quite sure why, and my experience is that something this stupid is going to come back and haunt me in a few weeks time, but I'm happy for the time being.
 
mpgalvin

Although you have decided to REPL... WITH, the following code might be useful, which answers your original question as to how get the calculation to work in the .KeyPress event.

In the .When() event of THISFORM.Grid1.Column2.Text1 put:-

THIS.Comment = []

In the .KeyPress() event THISFORM.Grid1.Column2.Text1 put:-

DO CASE
CASE nKeyCode = 127 && Backspace deletes old value
[tab]THIS.Value = 0
[tab]nVal = 0
CASE EMPTY(THIS.Value)
[tab]nVal = nKeyCode - 48
CASE nKeyCode = 46
[tab]nVal = THIS.Value
[tab]THIS.Comment = [1]
CASE THIS.Comment = [1]
[tab]nVal = (THIS.Value) + ((nKeyCode - 48) / 10)
[tab]THIS.Comment = [2]
CASE THIS.Comment = [2]
[tab]nVal = (THIS.Value) + ((nKeyCode - 48) / 100)
OTHE
[tab]nVal = (THIS.Value * 10) + (nKeyCode - 48)
ENDC

REPL TABLENAME.FieldC WITH TABLENAME.FieldA - nVal
THISFORM.Grid1.Refresh()

In the .LostFocus() THISFORM.Grid1.Column2.Text1 event put:-

THIS.Comment = []

The advantage it has over using the .LostFocus event or REPL... etc is that you can see the result of the calculation as the data is entered by the user.

Backspace clears the entry in the event of an error.

Chris :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top