New call-to-action
Results 1 to 7 of 7

Thread: How to get pointer to child table from a <form> pointer

  1. #1
    "Certified" Alphaholic
    Real Name
    Andrew Schone
    Join Date
    Dec 2005
    Location
    Kansas
    Posts
    1,048

    Default How to get pointer to child table from a <form> pointer

    I would like to open a form, that is based on a set. Filter the parent table to a particular record. Filter the child table to a particular record. End result is a form that is open displaying only one Parent record and only one child record associated with the parent record.

    I have been struggling with this all week trying to use form.viewqueried() with no successful. Looking at the documention and what my requirements are I believe that i need to use flattenquery here but always got error messages.

    So I decided to approach from a different angle.

    Open the form with form.load()
    Get a pointer to the parent table with <object>.table_get()
    run a <tbl>.query_create() to filter down to the desired parent record.

    Get a pointer to the child table with ??
    Run a <tbl>.query_create() to filter down to the desired child record.

    How do I get a pointer to the child table? I believe I will have a pointer to the form, from the form pointer can I get a pointer to the child table?

    With the description of what i want in the end, is this a viable method to accomplish it? Or should I revert back to the form.viewqueried() function?

  2. #2
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: How to get pointer to child table from a <form> pointer

    Not sure how it will work in practice but

    ptr = set.current() - pointer to set
    tbl = table.current(1) - pointer to topmost child as seen in set editor
    tbl = table.current(2) - pointer to next highest child as seen in set editor
    etc

    Just noticed this as well.

    You can also get a pointer to an open table using the TABLE.GET() method. For example, if you have opened a set and you want to get a pointer to one of the child tables in the set, (say "Invoice_Items"), you could use this command:

    child = table.get("invoice_items")

  3. #3
    "Certified" Alphaholic
    Real Name
    Andrew Schone
    Join Date
    Dec 2005
    Location
    Kansas
    Posts
    1,048

    Default Re: How to get pointer to child table from a <form> pointer

    Thanks for the reply Stan.

    set.current() returned the wrong set info. This is because the script that I am writing will be ran from a different form that is based on a different set. Set.current() is returning the set info of the set that is already opened, not the set that the form I am loading is based on. (hope that makes sense, i can re-explain if not).

    I tried to use the table.get() and received this error message
    Code:
    Error # 1002
    No such table
    Script: test
    Line #: 17
    From the <object>.table.get() they have an example of getting a table pointer via a browse object on the form
    Code:
    Example
    
    dim tptr as P
    
    tptr = Customer_Information:browse1.Table_Get()
    
    ? tptr.name_get()
    
    = "CUSTOMER"
    gonna give that a whirl and see what I can't break.

  4. #4
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: How to get pointer to child table from a <form> pointer

    gonna give that a whirl and see what I can't break.
    That's what makes life interesting.

  5. #5
    VAR
    Real Name
    Cheryl Lemire
    Join Date
    Jul 2003
    Location
    Pembroke Pines, FL
    Posts
    2,914

    Default Re: How to get pointer to child table from a <form> pointer

    Hi Andy,

    If your child filter is always going to be constant, you can set it in the filter of your set design for the child table. Example: I want to select a person and then only show the work phone number for that person selected. In my set design for the child table link I added a filter for the phone number type field that equals "work".

    Not sure exactly what your filtering expectations are on the parent or child so it is difficult to give much more info at this point.

    You could probably also run a query on your destination set with the filters you need for the parent and child table fields, then load the form based on that filter.
    Cheryl
    #1 Designs By Pagecrazy
    http://pagecrazy.com/

  6. #6
    "Certified" Alphaholic
    Real Name
    Andrew Schone
    Join Date
    Dec 2005
    Location
    Kansas
    Posts
    1,048

    Default Re: How to get pointer to child table from a <form> pointer

    Cheryl -

    The filter has to be dynamic to a point. The child table I only want the record where a particular field is blank. So in my first attempts, I placed the filter on the form using the form properties | filter/order tab.

    This worked in that I was able to query the parent table for the needed parent record and then only the child records that needed editing showed. I didnt like this approach because once the field was populated the form filter caused that particular record to dissappear (b/c it no longer matched the filter). Which is why I am having to be more specific and dynamic in my child filter.

    So far in my initial testing the
    Code:
    Example
    dim tptr as P
    tptr = Customer_Information:browse1.Table_Get()
    ? tptr.name_get()
    = "CUSTOMER"
    is working for me. Once I have a pointer to the child table I can place a query on the table using table.query_create() with the query that I need.

    thank you for the help
    -Andy

  7. #7
    "Certified" Alphaholic
    Real Name
    Andrew Schone
    Join Date
    Dec 2005
    Location
    Kansas
    Posts
    1,048

    Default Re: How to get pointer to child table from a <form> pointer

    Woot!

    Got the filter to work, thanks for the help :)

    Below is a copy of the code incase someone else is looking for way to do this.

    The only thing I need to work on next is how to refresh the subform on the form that I am opening. The form that I open has both an embedded browse and a subform based on the child record. The browse only shows the child record that matches the filter. The subform needs to be refreshed somehow so that it shows the proper data. Right now I just press "F5" once the form is open to refresh the subform.

    Thank you for the help :)

    -Andy

    Code:
    'Date Created: 04-Dec-2007 09:09:09 AM
    'Last Updated: 07-Dec-2007 02:07:49 PM
    'Created By  : AWS
    'Updated By  : AWS
    OPTION STRICT
    OPTION ENCRYPTED_TOKENS
    ON ERROR GOTO ERR_HANDLER
    
    Dim invoice_hdr as P
    invoice_hdr = table.current(1)
    
    if Invoice_hdr.PD_Desc = "Delivery" .and. Invoice_hdr.Tax_location = "" then
    	dim msg as C
    	msg = "Tax Jurisdiction is blank"
    	msg = msg + crlf(2) + "Update customer shipping address to include a tax jurisdiction"
        ui_msg_box("Error", msg)
    	
    	dim frm as P
    	frm = form.load("customer_frm","dialog")
    
    	dim cust_hdr as P{
    	cust_hdr = frm.table_get()
    	
    	dim cust_dtl as P
    	cust_dtl = frm:browse1.Table_get()
    	
    	dim query.description as C
    	dim query.order as C
    	dim query.filter as C
    	dim query.options as C
    	query.description = "blank tax jurisdiction"
    	query.order = "recno()"
    	query.filter = "unique_id = " + quote(invoice_hdr.cust_id)
    	dim hdr_indx as P
    	hdr_indx = cust_hdr.query_create()	
    
    	query.description = "blank tax jurisdiction"
    	query.order = "recno()"
    	query.filter = "Addr1 =" + quote(invoice_hdr.c_addr1) + ".and. Addr2 =" + quote(invoice_hdr.c_addr2) 
    	query.filter = query.filter + ".and. ST =" + quote(invoice_hdr.c_st) + ".and. zip=" + quote(invoice_hdr.c_zip)
    	ui_msg_box("",query.filter)
    	dim dtl_indx as P
    	dtl_indx = cust_dtl.query_create()	
    
    	frm.show()
    
    	hdr_indx.drop()
    	dtl_indx.drop()
    	
    	if is_object(frm) = .t. then 											     frm.close()
    	end if
    	
    end if
    END
    '-----------------------------------
    'Error handler
    '-----------------------------------
    ERR_HANDLER:
    	Dim err as N= error_code_get()
    	Dim msg as C= "Error # "+ err + crlf() + error_text_get(err)
    	msg = msg + crlf() + "Script: " + error_script_get()
    	msg = msg + crlf() + "Line #: " + error_line_number_get()
    	
    	ui_msg_box("Error", msg, ui_attention_symbol)
    	msg = ""
    
    	if is_object(frm) = .t. then 																									
    		frm.close()
    	end if
    
    	END

Similar Threads

  1. Error with table pointer
    By mstricky in forum Application Server Version 8
    Replies: 2
    Last Post: 11-21-2007, 05:07 PM
  2. Child Table Browse pointer table.current(2) lost
    By Mike Wilson in forum Alpha Five Version 7
    Replies: 7
    Last Post: 10-31-2006, 12:58 PM
  3. Need Help with Table Pointer
    By BillCampbell in forum Alpha Five Version 6
    Replies: 2
    Last Post: 12-16-2005, 01:35 AM
  4. Table Pointer error
    By Wanda Tucker in forum Web Application Server v6
    Replies: 0
    Last Post: 05-26-2005, 03:27 PM
  5. v4.5 closing form an error getting table pointer
    By Jim Chapman in forum Alpha Five Version 4
    Replies: 4
    Last Post: 02-16-2001, 08:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •