Normal Topic Bob Hansen - a followup question on 'on form entry (Read 2014 times)
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Bob Hansen - a followup question on 'on form entry
Feb 27th, 2009 at 5:22am
Print Post Print Post  
"I use @FormFieldValue function.
Here is some old code from a subform.  It is in OnFormEntry section:

It is a subform that is naturally linked to ClientNumber, but I like to have an element with the "Key Value" on the subform also.  On the subform, ClientNumber is ReadOnly.  The Parent form is named frmClients."

Bob, I 'add a new record in Purch (the Parent), then tab into POLines (the child subform) to add records of products (line items) to be ordered.  I have an "Add a New Line Item" command button in my subform that saves the current subform record, and creates a new record so I can enter an new line item.  

the PONum programming to link the parent po# with the child PONum field works fine on the first subform record, but it doesn't fire on additional subform records.  
         With what I'm trying to do, I'm think that I should be using a 'record' function instead of a 'form' function? .... so that each line item (subform record) fires its own po# value in the PONum field.

UPDATE:
I added the PONum = FormFieldValue("Purch", "PONum", 0) to the ItemNum 'on element change' , and it seems to work reliably ... am I missing a pitfall somewhere?

IF @isNew then
     
     {
           XLOOKUP (@fn, ItemNum, "INVENTORY!ItemNum", "ItemDesc", ItemDesc)
           XLOOKUP (@fn, ItemNum, "INVENTORY!ItemNum", "ItemCurrentCost", ItemCost)
           XLOOKUP (@fn, ItemNum, "INVENTORY!ItemNum", "ItemUoM", ItemUoM)
           PONum = @FORMFIELDVALUE("Purch","PONum",0)
     }
  

Larry
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
a followup question on 'on form entry
Reply #1 - Feb 27th, 2009 at 5:14pm
Print Post Print Post  
Since you are adding the line item with button code, I don't know what code you are using to add the additional records, but I suspect you may be opening the subform in StandAlone Mode.  Even in StandAlone mode, the OnFormEntry code should trigger, but, in that case, there may notl be a correct ParentForm associated with the line item. As a true subform, each PO Line Item record should be a single form, but your design may not look like that.

Triggering the code OnElementChange for the line item will probably be OK.  There is no "right way" to trigger any code, it will all depend on the specific design and what you want to do.  In my opinion,  most unique "record" elements should probably be triggered on form events, and most other element values would probably trigger on other element events.  

I usually prevent subforms from opening in StandAlone mode for data entry, only allow them to open in StandAlone for entering Retrieve specs and read only browsing.  Here is some sample code from the same form subform I used earlier:

Code
Select All
//StandAlone Form Conditions
If @FormIsStandalone() = 1 Then {

       // Prohibit Saving and Deleting
	NotifyForm(1)
	NotifyForm(4)
	@MsgBox("This data can only be added/modified using the Clients Form","","")

	// Show Audit Tracking elements
	Visibility(ClientNumber,1)
	Visibility(AddedBy,1)
	Visibility(DateAdded,1)
	Visibility(TimeAdded,1)
	Visibility(ChangedBy,1)
	Visibility(DateChanged,1)
	Visibility(TimeChanged,1)
	Visibility(Record,1)
	Visibility(RecordSource,1)

	ReadOnly(ClientNumber,1)
	ReadOnly(TaxYear,1)
	}

If @FormIsStandalone() = 0 Then {

	// Enable Save/Delete
	NotifyForm(0)

	// Hide Audit Tracking elements
       Visibility(ClientNumber,0)
	Visibility(AddedBy,0)
	Visibility(DateAdded,0)
	Visibility(TimeAdded,0)
	Visibility(ChangedBy,0)
	Visibility(DateChanged,0)
	Visibility(TimeChanged,0)
	Visibility(Record,0)
	Visibility(RecordSource,0)

	ReadOnly(ClientNumber,1)
	ReadOnly(TaxYear,1)
	} 




May I also suggest, that you do not limit your forum queries to any one individual in the Subject line.  
You are apt to get many more inputs from many users if you are open to all inputs.
« Last Edit: Feb 28th, 2009 at 1:24am by Bob_Hansen »  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: Bob Hansen - a followup question on 'on form e
Reply #2 - Feb 28th, 2009 at 4:46am
Print Post Print Post  
Bob,  forum protocol acknowledged!

Tomorrow I will post the code I used to generate new line items in my subform, in the event I'm wandering down the wrong road (not using it standalone now, but appreciate the code help to prevent standalone use).

  

Larry
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: Bob Hansen - a followup question on 'on form e
Reply #3 - Mar 3rd, 2009 at 4:52am
Print Post Print Post  
Bob,
here is the code I have in my command button to Add a New Line Item to my subform ....

var vTemp as Int //this button will save the current LineItem record and then add a new record

//      If (@Mode() = 0) Or (@Mode() = 1)
//      {
//            FormCommit("")
//      }
//      
     If (@Mode() = 0) Or (@Mode() = 1)
     {
           vTemp = @CreateNewRecord()
           ThrowFocus(ItemNum)
     }
  

Larry
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Bob Hansen - a followup question on 'on form e
Reply #4 - Mar 3rd, 2009 at 3:49pm
Print Post Print Post  
The sample I had provided was based on being in the Parent Form and moving the cursor into the sub form creating records in sequence.  The code was triggered by OnFormEnter programming i the subform.  But, by using @CreateNewRecord, that is like opening the sub form in standalone mode, but you are not actually opening the sub form so that code does not apply.

If using @CreateNewRecord you should probably include some code in the button that triggers this.  You should probably get the current PO number from the current Purchase Order, and make it into a Global Variable.  Then use the Global value to put into the PO number element on the subform vs. using FormFieldValue from the Parent form.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: Bob Hansen - a followup question on 'on form e
Reply #5 - Mar 3rd, 2009 at 6:59pm
Print Post Print Post  
Advice appreciated, Bob.

In an attempt to bolster my woefull rookie-itis, what is the theory behind the merit of using the Global value inserted in the PONum subrecord field, vs using FormFieldValue on the Parent ?
  

Larry
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Bob Hansen - a followup question on 'on form e
Reply #6 - Mar 3rd, 2009 at 7:37pm
Print Post Print Post  
I don't know how this is all structured, where your buttons are, etc.  They coudl be on the Parent form, could be on the POLine subform, could be on any other form, could be a Menu Option, etc.  Could be more than one that do the same thing.  I am concerned that you could start on one PO, perhaps close the parent or navigate to a different form/PO by mistake, and click a button to add a PO LIne.  so, the original PO might not be the current one.  Not knowing your design, I can't tell you when to save the PO as a global, but I would suspect when OnFormEnter you update the Global Value if you decide to use one.  

My designs don't use a button to Add a Record,  I just enter data into a field on the subform and it is created.  Go to the next record and add data into a filed, it is created.  It can have defaults, auto fills, dittos, etc.  No need to click on a button.  Just type data, press the down arrow if in Table View, and start typing into the next record.  Creating records this way guarantees you are in the correct PO form and you can use FormFieldValue safely because the subrecord is linked to the parent record.


  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: Bob Hansen - a followup question on 'on form e
Reply #7 - Mar 3rd, 2009 at 11:47pm
Print Post Print Post  
Hi Bob,

keeping in mind that I'm in beginning draft stages, just trying out different programming techniques and then seeing how they perform, here is an html page showing my PO layout with subform record

http://www.wordcom.com/POscreen.htm

It mimics to quite a degree the PO screen my employees are used to seeing in Q&A.  I plan on perusing other PO screen layouts/concepts as I get further up my programming learning curve.
  

Larry
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Bob Hansen - a followup question on 'on form e
Reply #8 - Mar 4th, 2009 at 12:46am
Print Post Print Post  
We could discuss designs forever and there is no "right" answer, but thanks for the picture.
I have included it here, better to see in message vs. need to jump to another web page.
(Edit: A replacement image was placed here on 3/6/09 per request of lksseven).
 

I am no sure that you still have a problem, I see the PO number on the subform.  I thnk we got sidetracked about comparing GlobalValue vs. FormFieldValue.

It looks like you have the Add PO Line button on your subform.  If that is using CreateARecord then the programming in OnFormEnter will not be executed when the record is created.  You will have to put the code into the button that would normally go into OnFormEnter.  If you do that, you can use FormFieldValue vs. GlobalValue, easier to code, only needed on subform.  

So, problem solved?
« Last Edit: Mar 7th, 2009 at 12:55am by Bob_Hansen »  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: Bob Hansen - a followup question on 'on form e
Reply #9 - Mar 4th, 2009 at 1:32am
Print Post Print Post  
Bob, problem solved.  Thanks so much.

Can leave the screenshot up.  That cost is just a made up $, and anyway it would probably change before the weekend.

  

Larry
Back to top
IP Logged