This code works well in a browse by itself with a button to call a form using the "invoice_number" as a link.
It does not, if is embeded in a form.
It gets "("Error","Invoice_number does not exist.) as it is coded.
Obviously needs changes.
1 The error checking
2 The browse is not the topparent anymore
3 It must have a new code to derive the invoice_number
What are the changes? Or is there a simpler code to call a form from a button in a embeded browse?
I saw a thread using the spyglas on a field, But I need a button to open the form.
Here is the code sample.
FUNCTION DRIVLICNO_ButtonClick AS V ( event AS C, data AS C , row AS N )
'DESCRIPTION: Fired when a button is clicked on a column.
'Arguments: event - the name of the event that is fired
' data - the data in the column cell
' row - the row number in the browse
'this.SetViewport_Row() sets the current row to the row with the button that was clicked.
this.Set_Viewport_row(row)
'Open a Form or Browse layout, displaying all, or selected records in the layout.
'Check to see if you are running the script from within a Form
dim flag_error as l
flag_error = .f.
if is_object(topparent.this) then
p = topparent.this
if eval_valid("P:Invoice_number.value") then
DELETE Parameter1
'Set the Parameter variable to the object's .value property
Parameter1 = eval("P:Invoice_number.value")
else
flag_error = .t.
end if
else
flag_error = .t.
end if
if flag_error then
ui_msg_box("Error","Invoice_number does not exist. This script cannot be run in this context.",UI_STOP_SYMBOL)
end
end if
filter = "Invoice_number = [varC->parameter1]"
query.filter = replace_parameters(filter,local_variables())
query.order = ""
'Open the layout_type showing just the records that satisfy the filter
DIM Shared varP_InvoiceAdd as P
DIM layout_name as c
layout_name = "InvoiceAdd"
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
dim flagIsBaseFilter as l
flagIsBaseQuery = .t.
if flagIsBaseFilter then
'Apply the query to the form or browse as the Base query. (this means that
'the user cannot turn the query off, only add to the query)
tempP.BaseQueryRun(query.filter,query.order)
else
tempP.QueryRun(query.filter,query.order)
end if
'then activate the already open window
tempP.activate()
else
'Window is not already open, so open it
varP_InvoiceAdd = :Form.viewqueried(layout_name,query.filter, query.order )
end if
else
varP_InvoiceAdd = :Form.viewqueried(layout_name,query.filter, query.order )
end if
END FUNCTION
'==============================
It does not, if is embeded in a form.
It gets "("Error","Invoice_number does not exist.) as it is coded.
Obviously needs changes.
1 The error checking
2 The browse is not the topparent anymore
3 It must have a new code to derive the invoice_number
What are the changes? Or is there a simpler code to call a form from a button in a embeded browse?
I saw a thread using the spyglas on a field, But I need a button to open the form.
Here is the code sample.
FUNCTION DRIVLICNO_ButtonClick AS V ( event AS C, data AS C , row AS N )
'DESCRIPTION: Fired when a button is clicked on a column.
'Arguments: event - the name of the event that is fired
' data - the data in the column cell
' row - the row number in the browse
'this.SetViewport_Row() sets the current row to the row with the button that was clicked.
this.Set_Viewport_row(row)
'Open a Form or Browse layout, displaying all, or selected records in the layout.
'Check to see if you are running the script from within a Form
dim flag_error as l
flag_error = .f.
if is_object(topparent.this) then
p = topparent.this
if eval_valid("P:Invoice_number.value") then
DELETE Parameter1
'Set the Parameter variable to the object's .value property
Parameter1 = eval("P:Invoice_number.value")
else
flag_error = .t.
end if
else
flag_error = .t.
end if
if flag_error then
ui_msg_box("Error","Invoice_number does not exist. This script cannot be run in this context.",UI_STOP_SYMBOL)
end
end if
filter = "Invoice_number = [varC->parameter1]"
query.filter = replace_parameters(filter,local_variables())
query.order = ""
'Open the layout_type showing just the records that satisfy the filter
DIM Shared varP_InvoiceAdd as P
DIM layout_name as c
layout_name = "InvoiceAdd"
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
dim flagIsBaseFilter as l
flagIsBaseQuery = .t.
if flagIsBaseFilter then
'Apply the query to the form or browse as the Base query. (this means that
'the user cannot turn the query off, only add to the query)
tempP.BaseQueryRun(query.filter,query.order)
else
tempP.QueryRun(query.filter,query.order)
end if
'then activate the already open window
tempP.activate()
else
'Window is not already open, so open it
varP_InvoiceAdd = :Form.viewqueried(layout_name,query.filter, query.order )
end if
else
varP_InvoiceAdd = :Form.viewqueried(layout_name,query.filter, query.order )
end if
END FUNCTION
'==============================
Comment