Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Having trouble with form events and field events

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Having trouble with form events and field events

    I am trying to have an event save a calculated field to a field

    The form �TracNew� is based on a set (one to many, linked on ID) named wtc_exp that has two tables:
    1. Wtcinv
    2. Expenses
    Wtc_exp has five fields:
    1. ID
    2. Date
    3. Type
    4. Description
    5. Amount

    The form �TracNew� has an embedded browse that has the five fields from the table wtc_exp. When an expense record is entered in the embedded browse, I would like to have a field on the above form to keep a running total of expenses for that inventory item. I have been able to do this with the following calculated field and the form:
    Tot_Exp = Total(Expenses->Amount,Grp->wtcinv)

    The problem with using a calculated field is that I am not able to use that �running total calculation� in other reports, browses, or forms.

    So I added a field to the form called �repairs� that I have tried to copy the calculated field �Tot_Exp� with form events or field events and I can�t get it to work.

    In the form event cansave I have:
    tbl = table.current()
    tot_exp.value = tbl.repairs


    or what I would prefer is on the Calculated field �Tot_Exp� onchange event:
    tbl = table.current()
    tot_exp.value = tbl.repairs

    Any ideas on what I'm missing

    Thanks
    Tony

    #2
    Re: Having trouble with form events and field events

    you can do that with action scripting. copy the contents of the calc field in a variable. and the set the contents of whatever field with the variable. 2 steps, easy done.
    need the calc field name in the form and the foem name of the other field.
    Dave Mason
    [email protected]
    Skype is dave.mason46

    Comment


      #3
      Re: Having trouble with form events and field events

      So I added a field to the form
      Not sure what you mean. Fields on forms can be table fields or variables. Did you add a field to the table and place it on the form? Are you trying to copy the calculated field value to the new table field?

      tbl = table.current()
      tbl.repairs = tot_exp.value
      There can be only one.

      Comment


        #4
        Re: Having trouble with form events and field events

        Stan,
        I did add a field (repairs) to the parent table and placed it on the form (TracNew), and yes, I'm trying to copy the calculated field (tot_exp) value to the new table field (repairs).

        Dave,
        I think I'm close with the event method, but I'll take a look at doing it with a variable.

        Thanks
        Tony

        Comment


          #5
          Re: Having trouble with form events and field events

          I think you had your assignment backwards

          Code:
          In the form event cansave I have: 
          tbl = table.current()
          tot_exp.value = tbl.repairs
          That says take the contents of tbl.repairs and put it in the tot_exp value property.
          There can be only one.

          Comment


            #6
            Re: Having trouble with form events and field events

            Stan
            I made the change:

            tbl = table.current()
            tbl.repairs = tot_exp.value

            Kinda works. When a value is entered in the embedded browse field amount, the calculated field tot_exp reflects the entry. The table field repairs does not. However, if I delete the "0" in the repairs field, then hit save, it works (same as calculated field)

            I need it to work as soon as the calculated field changes, without any other user input or effort.

            Also, entries in the embedded browse are on going. Added to and changed on a daily basis.

            Thanks
            Tony

            Comment


              #7
              Re: Having trouble with form events and field events

              I need it to work as soon as the calculated field changes
              To do that the code would have to be on a browse event, not a form event. I don't think you'll find one that fires when a single field/column value changes.
              There can be only one.

              Comment


                #8
                Re: Having trouble with form events and field events

                Stan
                How about the onchange event for the calculated field tot.exp? I have tried that and it is not working either.
                Tony

                Comment


                  #9
                  Re: Having trouble with form events and field events

                  Tony,

                  (Save) Button code is better because It will not fire until changed the parent records. see below code.

                  'It wrote by Someone, not me and purpose is
                  'You could do it in the OnSave event for the form. If your calculated total is displayed then that object has a value.
                  'Try a table.change_begin() to pass that value to the field you want to update.


                  dim tbl as p
                  dim vTotal as n
                  dim commit_flag as L
                  vTotal = parentform:xTotalLine.value

                  ui_msg_box("test",vTotal) 'test,
                  '(1) after changed the child records, the cal_value was changed then press F9 save key, you cannot see this message
                  '(2) However, after change the parent records, press F9 key, then you can see this message.

                  tbl = table.current(1) 'should always be the header or parent table
                  on error goto ERRMSG
                  commit_flag =.t.
                  tbl.change_begin()
                  tbl.total = vTotal
                  tbl.change_end(commit_flag)
                  parentform.Resynch()
                  parentform:total.refresh()
                  end
                  ERRMSG:
                  commit_flag = .f.
                  RESUME NEXT
                  'The above code, will fire after changed the parent's record. The F9 key will not fire it.
                  Or from LearnAlpha; Saving an Invoice total into invoice header
                  The Total Button OnPush Event Script follows:

                  ''XBasic Save Total button OnPush Script
                  dim hdr as p
                  sys_send_keys("[F9]") 'this commits the record
                  hdr=table.current() 'sets the hdr pointer to the Invoice_header table
                  hdr.change_begin() 'start the change method
                  hdr.invoice_total=Inv_Total.value 'the calculated total from the form is
                  ' in the Invoice_total field
                  hdr.change_end(.t.) 'end the change method
                  invoice_total.refresh() 'refreshes the total field in the form body

                  Comment


                    #10
                    Re: Having trouble with form events and field events

                    John, I'm not sure I follow your example or at the least, I would have a hard time getting it into my form.
                    Any other ideas on how to mirror a calculated field to a table field?
                    Thanks
                    Tony

                    Comment


                      #11
                      Re: Having trouble with form events and field events

                      Tony,

                      Create a Button and use the button event, onPush,, insert this code with modification.


                      Code:
                      ''XBasic Save Total button OnPush Script
                      
                      'Just test purpose
                      vCalValue = parentform:Tot_exp.value
                      ui_msg_box("test",vCalValue) 'test You can erase it later 
                      
                      dim tbl as p
                      tbl = table.current()         'sets the hdr pointer to the Invoice_header table
                            tbl.change_begin()          'start the change method
                                 tbl.repairs =  tot_exp.value           'the calculated total from the form is in the Invoice_total field
                            tbl.change_end(.t.) 'end the change method
                      
                      (Your Field_name) tot_exp.refresh() 'refreshes the total field in the form body
                      Let me know and show me the screen shot or something if you still have the trouble.

                      Comment


                        #12
                        Re: Having trouble with form events and field events

                        Tony,

                        Check your field object name too

                        Comment


                          #13
                          Re: Having trouble with form events and field events

                          John and others,
                          I think I have found a solution to my problem. After finding some advice that Tom Cone had given on another thread about putting the code in the onsave event for the embedded browse, my form field is getting changed immediately.
                          Thanks!!
                          Tony

                          Comment

                          Working...
                          X