![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
method action(var eventInfo ActionEvent) var tc2 tCursor endVar if eventInfo.id()=dataInsertRecord then DoDefault if not tc2.open(":MONEY:EntryNum.DB") then errorShow() endIf EntryNumber = tc2.entryNum tc2.edit() tc2.entryNum = EntryNumber + 1 edit() entry = tc2.entryNum tc2.endEdit() tc2.close() endIf endMethod |
#2
| |||
| |||
|
|
On Fri, 09 Jan 2009 08:53:02 -0700, Tony McGuire png.paradoxcommunity@com> wrote: Kenneth wrote: method action(var eventInfo ActionEvent) var tc2 tCursor endVar if eventInfo.id()=dataInsertRecord then DoDefault if not tc2.open(":MONEY:EntryNum.DB") then errorShow() endIf EntryNumber = tc2.entryNum tc2.edit() tc2.entryNum = EntryNumber + 1 edit() entry = tc2.entryNum tc2.endEdit() tc2.close() endIf endMethod You have 'edit()' as part of the routine INSIDE the if eventinfo.id() block. Are you sure it is in edit mode to start with? Cause the above would fail the first time and work (likely) the second and subsequent times (sound like what you are getting?) if the form wasn't in edit to start. Also, if the tc2.open you have errorshow(); I would add 'return' to that since you don't want errors cropping up when your code starts referencing a tcursor that didn't get opened. Is this code going to be used by more than one person; ever? Actully, the table 'entrynumb.db'. If so, this code needs (critically) to be revisited once you get the main issue resolved. Hi Tony, I removed the endEdit() as you suggested. Now, if I launch the form, and touch the Insert Key, a new blank record opens as it should, but the Entry Number increments by 2, rather than 1. If I then populate that record, and touch Insert again, a new blank record opens and the counter increments by 1. Also, this is STRICTLY a one person form, and so there is no issue with regard to properly locking the entrynum.db. Very sincere thanks for your help, -- Kenneth If you email... Please remove the "SPAMLESS." |
#3
| |||
| |||
|
|
Actually, Tony referred to the edit() statement, not the endedit. What exactly does an Edit() statement do without an associated object? I'm used to saying myTc.edit() or something like that so I know what exactly is going into edit mode. |
#4
| |||||||||
| |||||||||
|
|
method action(var eventInfo ActionEvent) var tc2 tCursor endVar if eventInfo.id()=dataInsertRecord then DoDefault ; The doDefault inserts the record /if/ the form is in edit mode. |
|
if not tc2.open(":MONEY:EntryNum.DB") then errorShow() endIf ; At this point tc2 is pointing to the table, but it is unclear |
|
EntryNumber = tc2.entryNum ; This should be the entryNum of whatever record is the first one in |
|
tc2.edit() ; This puts the *tCursor* into edit mode. |
|
tc2.entryNum = EntryNumber + 1 ; This alters the first record's entryNum by incrementing it. |
|
edit() ; This puts the *form* into edit mode. |
|
entry = tc2.entryNum ; At this point entry -- which I assume is a uiObject on the form that |
|
tc2.endEdit() ; This posts the change you made to the first record via the tCursor. |
|
tc2.close() endIf endMethod |
#5
| |||
| |||
|
|
Inline. On Fri, 09 Jan 2009 10:23:19 -0500, Kenneth wrote: method action(var eventInfo ActionEvent) var tc2 tCursor endVar if eventInfo.id()=dataInsertRecord then DoDefault ; The doDefault inserts the record /if/ the form is in edit mode. ; Otherwise, it fails, and no record has been added. if not tc2.open(":MONEY:EntryNum.DB") then errorShow() endIf ; At this point tc2 is pointing to the table, but it is unclear ; to me which record it is pointing to. I expect it points to the first ; record. EntryNumber = tc2.entryNum ; This should be the entryNum of whatever record is the first one in ; the table. tc2.edit() ; This puts the *tCursor* into edit mode. tc2.entryNum = EntryNumber + 1 ; This alters the first record's entryNum by incrementing it. ; Note that you are changing its primary key! edit() ; This puts the *form* into edit mode. entry = tc2.entryNum ; At this point entry -- which I assume is a uiObject on the form that ; corresponds to a field in the table -- equals the first record's ; entryNum, which you incremented three steps ago. tc2.endEdit() ; This posts the change you made to the first record via the tCursor. ; The change you made to the record shown by the form, which may or may ; not be a different record, has not yet been posted. tc2.close() endIf endMethod OK, lemme make a suggestion. First, I am assuming that entryNum is the table's primary key. This means that, when the tCursor opens on the table and points to the first record, it will be pointing to the record with the /lowest/ entryNum, and that the last record will be the one with the /highest/ entryNum. var flg logical tc2 tCursor li longint endVar flg = FALSE if not isEdit() then flg = TRUE edit() endif ;This lets us restore the user's edit setting at the end ;Now the form is in edit mode, and the insert can work. if eventInfo.id()=dataInsertRecord then ;The tCursor exists merely to get the highest value, ;so we do the tCursor thing /before/ creating the new record if not tc2.open(":MONEY:EntryNum.DB") then msgStop("Error","New record not created because the tCursor failed") return ;execution stops - no new record added endIf tc2.end() ;tc2 should now be pointing to the record with the highest entryNum li = tc2.entryNum tc.2.close() ;We are now back to the form, and using uiObjects DoDefault ;creates the new record li = li + 1 entry.value = li postRecord() ;pushes the new record into the table endif if flg then ;restore the user's edit setting endedit() endif Again, this is untested. The gist of it should be ok. I hope. -- Jim Hargan |
#6
| |||
| |||
|
|
On Fri, 9 Jan 2009 13:02:57 -0500, Jim Giner wrote: Actually, Tony referred to the edit() statement, not the endedit. What exactly does an Edit() statement do without an associated object? I'm used to saying myTc.edit() or something like that so I know what exactly is going into edit mode. Edit() without an associated object becomes a uiObject method, and (like all such 'bare' uiObject methods) is interpreted as self.Edit(). That is -- as far as I can figure out. Bare uiObject methods confused the heck out of me for many years, and this interpretation seems to work consistently. FWIW, -- Jim Hargan |
#7
| |||
| |||
|
|
Jim - I'm guessing that tc2 is pointing to a one record table - without a key. It's the way he increments his form's record keys. |
#8
| |||
| |||
|
|
if not tc2.open(":MONEY:EntryNum.DB") then errorShow() endIf |

#9
| |||
| |||
|
|
Tony McGuire Hi Tony, Well, I don't know about Nirvana, but I am pleased to have it working, and have incorporated your errorShow suggestion. Many thanks, as before, |
![]() |
| Thread Tools | |
| Display Modes | |
| |