Simple Multiple Frames?

Doug Johnson

New Member
I am displaying records from a table using a browse. When a user selects a browse row and clicks the "Find" button, another browse is displayed showing records from a related table. The user can then click a "Back" button and return to the original browse. This works, but only ONCE! After the return from the second browse, the "Find" button in the first browse no longer works. Andy ideas what might be wrong?

Code is below:

----------------------------

Code:
[/FONT][/SIZE]DEFINE VARIABLE method-return AS LOGICAL   NO-UNDO.
DEFINE VARIABLE tierverify    AS CHARACTER FORMAT "X(1)".

DEFINE QUERY query1 FOR tier-list SCROLLING.

DEFINE BROWSE browse1 QUERY query1 NO-LOCK DISPLAY tier-list.tier-code tier-list.tier-name tier-list.tier-float
  ENABLE tier-list.tier-code tier-list.tier-name tier-list.tier-float WITH
  13 DOWN
  WIDTH 45
  NO-ASSIGN
  SCROLLBAR-VERTICAL
  SEPARATORS.

DEFINE QUERY query2 FOR whstore SCROLLING.

DEFINE BROWSE browse2 QUERY query2 NO-LOCK DISPLAY whstore.part-num whstore.tier-code whstore.whse-loc whstore.skid-color
  ENABLE whstore.tier-code whstore.whse-loc whstore.skid-color WITH
  13 DOWN
  WIDTH 45
  NO-ASSIGN
  SCROLLBAR-VERTICAL
  SEPARATORS.

DEFINE BUTTON findbutton
  LABEL "FIND"
  FONT 2
  SIZE 12 BY 1.5.
DEFINE BUTTON backbutton
  LABEL "BACK"
  FONT 2
  SIZE 6 BY 1.5.

DEFINE FRAME frame1
  SPACE(15) "TIER MAINTENANCE" SKIP(.25)
  SPACE(1) findbutton
  SKIP(.25)
  browse1 SKIP(.25)
  WITH NO-BOX.

DEFINE FRAME frame2
  SPACE(1) backbutton
  SPACE(11) "TIER LOCATIONS" SKIP(.25)
  browse2 SKIP(.25)
  WITH NO-BOX.

MESSAGE "When Editing, Press ENTER or click outside row to update".

ON ROW-LEAVE OF browse1 IN FRAME frame1 /* No-Assign Browser */
  DO:
    /*################################*/
    /*###### INSERT NEW RECORD #####*/
    /*################################*/
    IF browse1:NEW-ROW THEN
    DO:
      CREATE tier-list.
      ASSIGN INPUT BROWSE browse1
        tier-list.tier-code
        tier-list.tier-name
        tier-list.tier-float.
      DISPLAY tier-list.tier-code tier-list.tier-name tier-list.tier-float WITH BROWSE browse1.
      method-return = browse1:CREATE-RESULT-LIST-ENTRY().
      RETURN.
    END.

    /*########################*/
    /*##### EDIT RECORD #####*/
    /*########################*/
    IF BROWSE browse1:CURRENT-ROW-MODIFIED THEN
    DO:
      GET CURRENT query1 EXCLUSIVE-LOCK.
IF CURRENT-CHANGED tier-list THEN
DO:
      MESSAGE "This record has been changed by another user."
        SKIP "Please re-enter your changes.".
      DISPLAY tier-list.tier-code tier-list.tier-name tier-list.tier-float WITH BROWSE browse1.
      RETURN NO-APPLY.
    END.
    ELSE /* Record is the same, so update it with exclusive-lock */
      ASSIGN INPUT BROWSE browse1 tier-list.tier-code tier-list.tier-name tier-list.tier-float.
    /* Downgrade the lock to a no-lock. */
    GET CURRENT query1 NO-LOCK.
  END.
END.

/*#######################*/
/*##### FIND MATCH #####*/
/*######################*/
ON CHOOSE OF findbutton IN FRAME frame1
  DO:
    GET CURRENT query1 EXCLUSIVE-LOCK NO-WAIT.
    tierverify = tier-list.tier-code.
      OPEN QUERY query2 FOR EACH whstore WHERE whstore.tier-code = tierverify.
    ENABLE ALL WITH FRAME frame2.
    WAIT-FOR WINDOW-CLOSE OF CURRENT-WINDOW.
  END.

/*###########################*/
/*##### BACK ################*/
/*###########################*/
ON CHOOSE OF backbutton IN FRAME frame2
  DO:
      OPEN QUERY query1 FOR EACH tier-list.
    ENABLE ALL WITH FRAME frame1.
  END.

  OPEN QUERY query1 FOR EACH tier-list.
ENABLE ALL WITH FRAME frame1.
WAIT-FOR WINDOW-CLOSE OF CURRENT-WINDOW.
 

Stefan

Well-Known Member
You are breaking the PEG golden rule: "one world, one wait-for".

You are shifting the wait-for from frame1 to frame2 when clicking on the FIND button. You do not need to be enabling and re-enabling everything, HIDE the old frame and VIEW the new frame. Before doing this you will want to add a PAUSE 0 BEFORE-HIDE to prevent the 'press space bar to continue' message.

Also, to help other reader, add the following before your example to allow instant try outs:

Code:
DEFINE TEMP-TABLE tier-list NO-UNDO
   FIELD tier-code AS CHAR
   FIELD tier-name AS CHAR
   FIELD tier-float AS CHAR
   .


CREATE tier-list. ASSIGN tier-code = "TC1" tier-name = "tname".
CREATE tier-list. ASSIGN tier-code = "TC2" tier-name = "tname".


DEFINE TEMP-TABLE whstore NO-UNDO
   FIELD part-num AS CHAR
   FIELD tier-code AS CHAR
   FIELD whse-loc AS CHAR
   FIELD skid-color AS CHAR
   .


CREATE whstore. ASSIGN part-num = "ABC1" whstore.tier-code = "TC1" whse-loc = "NZ".
CREATE whstore. ASSIGN part-num = "ABC2" whstore.tier-code = "TC1" whse-loc = "NZ".


CREATE whstore. ASSIGN part-num = "ABC3" whstore.tier-code = "TC2" whse-loc = "NZ".
CREATE whstore. ASSIGN part-num = "ABC4" whstore.tier-code = "TC2" whse-loc = "NZ".

I also do not see why you want to reopen the query when going back, I would expect back to return me to the screen as it was before I left it.

So here's my version (without the editing bit since it was not part of the question):

Code:
MESSAGE "When Editing, Press ENTER or click outside row to update".


/*##### FIND MATCH #####*/
ON CHOOSE OF findbutton IN FRAME frame1 DO:
   GET CURRENT query1 EXCLUSIVE-LOCK NO-WAIT.
   tierverify = tier-list.tier-code.
   OPEN QUERY query2 FOR EACH whstore WHERE whstore.tier-code = tierverify.
   VIEW FRAME frame2.
END.


/*##### BACK ################*/
ON CHOOSE OF backbutton IN FRAME frame2 DO:
   HIDE FRAME frame2. 
   VIEW FRAME frame1.
END.


OPEN QUERY query1 FOR EACH tier-list.


PAUSE 0 BEFORE-HIDE.


ENABLE ALL WITH FRAME frame2.
ENABLE ALL WITH FRAME frame1.


WAIT-FOR WINDOW-CLOSE OF CURRENT-WINDOW.

Also, looking over the code again I strongly doubt you want an EXCLUSIVE-LOCK on the query1 record while the user browses through the results of query2 at his leisure, this is asking for trouble!
 
Top