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

script on CanRecordDelete event gives error

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

    script on CanRecordDelete event gives error

    When I run this code through the interactive window:
    Code:
    	site = prospect->site_num             'makes the variable 'site' equal to the site number of the appointment
    	jsite = table.open("job_sites")
    	query.filter="site_num = var->site"
    	jsite.query_create()
    	jsite.change_begin()
    	jsite.Schd = .f.
    	jsite.change_end(.t.)
    	jsite.close()
    it does just what I want.
    But, when I put it in the CanDeleteRecord event, I get this error:
    Script:Table (Prospect)CanDeleteRecord line 13:
    jsite.query_create()
    no such field
    Anyone know why?
    I assume it's a problem with not recognizing the query.filter variables, but why does it work in the interactive window and not on the CanDeleteRecord event in field rules?


    P.S. As an expanation, I have jobsites for which I schedule appointments. When I schedule an appointment (prospect table), the jobsite is marked scheduled (schd = .t.). If I delete the appointment, I want the jobsite to be marked as not scheduled (schd = .f.), so I can re-schedule it another time.
    Brad Steinfeldt

    #2
    What data type is the site_num field?

    -- tom

    Comment


      #3
      Try:

      query.filter="site_num = '"+var->site+"'"
      or
      query.filter="site_num = '"+site+"'"


      Expanded view for readability (do not use in code):
      ' " + var->site + " ' "

      Comment


        #4
        It's all character type.
        Brad Steinfeldt

        Comment


          #5
          I tried both of these and neither worked.
          maybe this will help. . .
          In the interactive window, before the query_create(),

          query.filter = "site_num = '"+site+"'"
          ? query.filter
          = "site_num = '0689 '"
          after a successful query,
          = "site_num = '0689 '"
          ? jsite.site_num
          = "0689"

          while,
          query.filter = "site_num = site"
          ? query.filter
          = "site_num = site"

          after a successful query,
          = site_num = "0689 "
          ? jsite.site_num
          = "0689"

          Both work, and give me the same result, but when using it in the candeleterecord event, it gives me the "no such field" error.

          I ran the debugger, and before a successful query,
          query.filter = site_num = '0689 '

          when it hits the query create() line, I get the error.
          Brad Steinfeldt

          Comment


            #6
            Brad, I'll need to see the database to help on this. What you're reporting in the interactive editor doesn't make sense. ( I believe you, just think there's another explanation. ) You're not showing us the entire script that's running in the CanDeleteRecord event.

            -- tom

            Comment


              #7
              Brad

              Try using job_sites->site_num instead of site_num.

              If there is a set involved, you may need to provide the table name with the field name.

              I also find it helpful to open a default browse for the table/set that the query is based on and generate the query until it works the way I want. Then I write the filter using the query generated filter as a guide.
              Al Buchholz
              Bookwood Systems, LTD
              Weekly QReportBuilder Webinars Thursday 1 pm CST

              Occam's Razor - KISS
              Normalize till it hurts - De-normalize till it works.
              Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
              When we triage a problem it is much easier to read sample systems than to read a mind.
              "Make it as simple as possible, but not simpler."
              Albert Einstein

              http://www.iadn.com/images/media/iadn_member.png

              Comment


                #8
                I tried job_sites->site_num and the difference is the description of the error. This time, the error reads, "Field is not recognized".
                I did try creating the query through "query by expression" and I used it, but it just gave me what I'm working with right now.
                I'll have to pack up the tables and attach them to this thread.
                Thanks for your help.
                Brad Steinfeldt

                Comment


                  #9
                  I've uploaded the database (only problem is I don't know what I'm doing when I backup, so it's much bigger than it needs to be). Sorry.

                  To produce the problem, Open the appointment form, pick a record, and delete it.
                  Brad Steinfeldt

                  Comment


                    #10
                    I've attached file. Thanks for your interest.
                    Brad Steinfeldt

                    Comment


                      #11
                      Code:
                      'Date Created: 17-Mar-2006 07:12:47 AM
                      'Last Updated: 17-Mar-2006 11:33:27 PM
                      'Created By  : Brad
                      'Updated By  : TEC
                      
                      'Brad, a few general comments first.
                      '
                      'Your database name contains blank spaces.  This is NOT recommended.
                      'You have sets with names that are identical to tables.  This is NOT recommended.
                      '
                      'I renamed your "Job_Sites" set as "Job_Sites_Set"
                      'I renamed your "Prospect" set as "Prospect_set"
                      
                      'I revised your CanDeleteRecord event script for the Prospect table as shown below.
                      'Here are the highlights:
                      '   1) I prefer to use tbl pointer to the current instance of the Prospect table
                      '   2) You should always set ALL query parameters before running a query.  Alpha Five
                      '          will not re-run a query if the query list already exists.
                      '   3) I changed the way the filter expression is written.  It's dangerous to
                      '          include the target table name, since the alias may be different.  Here
                      '          the Job_sites table is open already, so this script will open another
                      '          instance and its alias will be "job_sites1", not "job_sites"
                      '   4) I included an error trap if the query fails
                      '   5) I blocked the delete if there is no matching record in the Job_sites table.  You may
                      '          not want to do this.
                      '   6) Since you're comparing the site_num in Prospect table with site_num field values in
                      '          the Job_Sites table it's vital that this field have the same characteristics
                      '          in each table.  I increased the field width for site_num in Job_sites table
                      '          so that it will match the width of the site_num field in Prospect table.  A
                      '          trailing space can cause a mismatch sometimes.
                      '
                      ' Ok, here's the revised script:
                      
                      tbl = table.current()  'get pointer to Prospect table
                      
                      ' if the appointment was created as a t-on/off then unschedule the jobsite
                      IF (left(tbl.Type_Of_Work,7)="Premium").or.(left(tbl.Type_Of_Work,7)="Regular")\
                      	.or.(left(tbl.Type_Of_Work,7)="Blow-ou") THEN
                      'debug(1)
                      
                      	site = alltrim(tbl.site_num)	'assign site_num to variable
                      	'trace.writeln("Selected site_num is: "+site)
                      	jsite = table.open("job_sites.dbf")	'open new instance of job_sites table
                      	'query.filter="job_sites->site_num = '"+site+"'"
                      	
                      	'set all query parameters
                      	query.filter="site_num = "+s_quote(site)
                      	query.options = "MT"
                      	query.order = ""
                      	'trace.writeln("query_filter: "+query.filter)
                      
                      	on error goto cancel_delete
                      	qry = jsite.query_create()
                      	on error goto 0
                      		
                      	if qry.records_get() > 0 then	'query found a job_sites record with same site_num
                      		msgbox("Hoorah!","The query ran fine")
                      		jsite.change_begin()
                      		jsite.Schd = .f.
                      		jsite.change_end(.t.)
                      	else
                      		msgbox("Oops","Query list is empty")
                      		cancel()  'cancel the delete, you may prefer to let the delete occur.
                      	end if
                      	qry.drop()	'cleanup on the way out
                      	jsite.close()
                      	
                      	xbasic_wait_for_idle()	'let the query and change finish before deleting prospect table record
                      	end	
                      end if
                      
                      cancel_delete:
                       jsite.close()	'query failed
                       cancel()  		'cancel the delete
                       err = error_code_get()
                       msg = error_text_get(err)
                       ui_msg_box("Error", msg + crlf()+crlf()+"Delete was cancelled")
                       end
                      -- tom

                      Comment


                        #12
                        I haven't looked at your script or the sample database but I'm wondering if it would work better in the OnDelete rather than the CanDelete event.

                        The primary purpose of the CanDelete is to decide whether or not the parameters are acceptable for deleting the record - if not, a "Cancel()" will stop the deletion.

                        The primary purpose of the OnDelete is to do something after a record has been deleted. In this case it may be necessary (but I don't think so) to save the value of the site number in a shared or "temporary" global variable so the OnDelete can use it. (By "temporary" I just mean it could be DELETEd when the OnDelete closes.)

                        Comment


                          #13
                          Cal, that's a good point. The CanDeleteRecord event could populate the variable for use when OnDeleteRecord fires. Otherwise, there's a risk the CanDeleteRecord script will modify other table values even when the user elects to cancel a delete.

                          Here, there were more fundamental problems relating to the query sequence that were causing the problem Brad was seeing.

                          -- tom

                          Comment


                            #14
                            Tom,
                            Thanks for looking into this and all the helpful suggestions. I haven't had time to go through them yet, but I wanted to thank you first.
                            The two biggest problem with my xbasic programing is I don't always understand sound fundamental basics. Second, I am working on an a5 app that has been played with for about 12-13 years, so there's some old, stupid mistakes still lingering that I haven't fixed.
                            I'm like the neighbor down the street that keeps making additions to his house with the crap that's he finds laying around. I see some cool stuff and want it, so I get out my hammer and nails and start pounding.
                            One of these days, I should re-structure it all over again from scratch and just piece in the sound working features. I'd probably learn alot by doing that.

                            Cal,
                            I see your point, and that was exactly why I chose the CanDelete event rather than OnDelete. I was trying to avoid referring to a deleted 'site_num'.
                            Once I get it working, I'll put it in the OnDelete to see if it's getting the right number or not. If it doesn't, I guess the best thing to do is assign the varable in the CanDelete event.
                            Brad Steinfeldt

                            Comment


                              #15
                              Tom, Cal, and all who are following this thread,

                              The script worked! Thanks so much. I'll try to remember to use a pointer and then declare all options of my query. good lesson!
                              It also works on the OnDeleteRecord event. It was able to collect the correct data for my query from the deleted record. I will assume that it runs the script just prior to completely deleting the record.
                              Brad Steinfeldt

                              Comment

                              Working...
                              X