From: jim.giner@suny.edu   
      
   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.   
   "Jim Hargan" wrote in message   
   news:15clbx9nh2zu5.7s6itx22fmcd.dlg@40tude.net...   
   > 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   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|