I created the script below using Action Scripting and I can't see why it won't work. I want to navigate to a specified record when switching from one form to another. I set the global variable, vn_rec_no, to the correct record number and use it to specify the record. Yet, when the new form opens, it always goes to the first record in the table.
The funny thing is that I can execute the Goto Record Number command as a script once the form is open and it works fine. I would appreciate any ideas on what I need to do to make this work.
'Open a Form or Browse layout, displaying all, or selected records in the layout.
DIM Shared varP_admin_frm as P
DIM layout_name as c
layout_name = "Admin_frm"
DIM tempP as p
'Get pointer to existing window. In case layout_name is qualified with a dictionary name, extract up to first @. In case formname has spaces, normalize it
tempP=obj(":"+object_Name_normalize(word(layout_name,1,"@")))
'Test if pointer is valid
if is_object(tempP) then
'Test if pointer refers to a form or browse
if tempP.class() = "form" .or. tempP.class() = "browse" then
'If so, then activate the already open window
tempP.activate()
else
'Window is not already open, so open it
varP_admin_frm = :Form.view(layout_name)
end if
else
varP_admin_frm = :Form.view(layout_name)
end if
'Set the index to : 'Log_Num' in current window.
topparent.Index_SetExplicit("")
'Go to a specified record number in current form at parent level.
DIM var_recno_target as N
var_recno_target = vn_rec_no
topparent.recno_goto(var_recno_target)
'Close the form/browse called: cut_log_frm
DIM window_to_close as C
window_to_close = "cut_log_2"
DIM varP_Window as p
'If the window name was specified without a leading ":", then add it.
if left(alltrim(window_to_close),1) <> ":" then
window_to_close = ":"+alltrim(window_to_close)
end if
'Get a pointer to the specified window
varP_Window = obj(window_to_close)
'Check if the specified window really exists
if .not. is_object(varP_Window) then
ui_msg_box("Error","Can not close the window 'cut_log_2' because it is not open.",UI_STOP_SYMBOL)
end
else
'Check to see that the object supports the "close()" method
if .not. varP_Window.has_method("close") then
ui_msg_box("Error","Can not close 'cut_log_2' because it is not a window.",UI_STOP_SYMBOL)
else
'The window does exist, so close it
'Check to see that the object supports the "mode_get()" method
if varP_Window.has_method("mode_get") then
'Save any unsaved data before closing the window
DIM mode as c
mode = varP_Window.mode_get()
if (mode = "ENTER" .or. mode = "CHANGE") then
varP_Window.commit()
'Check to see if the record was successfully saved
if varP_Window.mode_get()<>"VIEW" then
ui_msg_box("Unable to save your changes","Please correct and save, or discard your changes", UI_STOP_SYMBOL)
end
end if
end if
end if
'Close the window
varP_window.close(.f.)
end if
end if
The funny thing is that I can execute the Goto Record Number command as a script once the form is open and it works fine. I would appreciate any ideas on what I need to do to make this work.
'Open a Form or Browse layout, displaying all, or selected records in the layout.
DIM Shared varP_admin_frm as P
DIM layout_name as c
layout_name = "Admin_frm"
DIM tempP as p
'Get pointer to existing window. In case layout_name is qualified with a dictionary name, extract up to first @. In case formname has spaces, normalize it
tempP=obj(":"+object_Name_normalize(word(layout_name,1,"@")))
'Test if pointer is valid
if is_object(tempP) then
'Test if pointer refers to a form or browse
if tempP.class() = "form" .or. tempP.class() = "browse" then
'If so, then activate the already open window
tempP.activate()
else
'Window is not already open, so open it
varP_admin_frm = :Form.view(layout_name)
end if
else
varP_admin_frm = :Form.view(layout_name)
end if
'Set the index to : 'Log_Num' in current window.
topparent.Index_SetExplicit("")
'Go to a specified record number in current form at parent level.
DIM var_recno_target as N
var_recno_target = vn_rec_no
topparent.recno_goto(var_recno_target)
'Close the form/browse called: cut_log_frm
DIM window_to_close as C
window_to_close = "cut_log_2"
DIM varP_Window as p
'If the window name was specified without a leading ":", then add it.
if left(alltrim(window_to_close),1) <> ":" then
window_to_close = ":"+alltrim(window_to_close)
end if
'Get a pointer to the specified window
varP_Window = obj(window_to_close)
'Check if the specified window really exists
if .not. is_object(varP_Window) then
ui_msg_box("Error","Can not close the window 'cut_log_2' because it is not open.",UI_STOP_SYMBOL)
end
else
'Check to see that the object supports the "close()" method
if .not. varP_Window.has_method("close") then
ui_msg_box("Error","Can not close 'cut_log_2' because it is not a window.",UI_STOP_SYMBOL)
else
'The window does exist, so close it
'Check to see that the object supports the "mode_get()" method
if varP_Window.has_method("mode_get") then
'Save any unsaved data before closing the window
DIM mode as c
mode = varP_Window.mode_get()
if (mode = "ENTER" .or. mode = "CHANGE") then
varP_Window.commit()
'Check to see if the record was successfully saved
if varP_Window.mode_get()<>"VIEW" then
ui_msg_box("Unable to save your changes","Please correct and save, or discard your changes", UI_STOP_SYMBOL)
end
end if
end if
end if
'Close the window
varP_window.close(.f.)
end if
end if
Comment