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

Usps_city_from_zip() ?

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

    Usps_city_from_zip() ?

    Hi All,

    I have a customer table and I am using USPS_CITY_FROM_ZIP() and USPS_STATE_FROM_ZIP() functions, I have placed each function in the default value field in the table for each field, my problem is it only works if the city and state field get focus after entering the zip code and only when entering a new record not allowing the city and state field to change if we change the zip later on.

    What I would like to do is have the USPS_CITY_FROM_ZIP() and USPS_STATE_FROM_ZIP() functions fire and set the city and state field as soon as the zip code field looses focus all the time not just when adding a new record, could someone please show me how to write an xbasic script and where I should place it at the table level that will work all the time no matter what field gets focus after the zip is updated or entered for the first time.
    Kind Regards,
    Ray Roosa
    Raylin Micro, LLC.

    #2
    Re: Usps_city_from_zip() ?

    Ray

    Using a default value in field rules will only fire when the record is first entered. After that it will not. So the default is doing what it is supposed to do.

    To get the city to change when changing the zip code you would have to use a calculated field in the field rules or put an on change event in the zip code field to update the city and state fields when the zipcode changes but leave the default in the field rules.

    In the onchange event for the zip code field

    Code:
    :formname.city.value=usps_city_from_zip("zipcode")
    :formname.state.value=usps_state_from zip("zipcode")
    Where formname is the name of your form - replace city and state with the field you have in your table.
    Tom
    Last edited by Tbaker; 05-30-2008, 10:34 AM. Reason: add further

    Comment


      #3
      Re: Usps_city_from_zip() ?

      Originally posted by Tbaker View Post
      Ray

      Using a default value in field rules will only fire when the record is first entered. After that it will not. So the default is doing what it is supposed to do.

      To get the city to change when changing the zip code you would have to use a calculated field in the field rules or put an on change event in the zip code field to update the city and state fields when the zipcode changes but leave the default in the field rules.

      In the onchange event for the zip code field

      Code:
      :formname.city.value=usps_city_from_zip("zipcode")
      :formname.state.value=usps_state_from zip("zipcode")
      Where formname is the name of your form - replace city and state with the field you have in your table.
      Tom
      Tom,

      Thank you very much for the info, can I put this code at the table level so its not form dependent?
      Kind Regards,
      Ray Roosa
      Raylin Micro, LLC.

      Comment


        #4
        Re: Usps_city_from_zip() ?

        In the field rules you can make city and state a calculated field dependent upon the zipcode field.

        in the city calculated field expression you would show

        Code:
         usps_city_from_zip(zipcode)
        in the state calculated field expression you would show

        Code:
         usps_state_from_zip(zipcode)
        That way anytime the zipcode is changed the calculated field expression would lookup the city and the state and enter them in the appropriate fields on any form or browse connected to this table.

        However, if you have a form or a browse and the zipcode reflects a city that is not the one you want but is located in that zip code, you would not be able to change the city since it is a calculated field.

        Just a caution.

        Tom

        Comment


          #5
          Re: Usps_city_from_zip() ?

          Originally posted by Tbaker View Post
          In the field rules you can make city and state a calculated field dependent upon the zipcode field.

          in the city calculated field expression you would show

          Code:
           usps_city_from_zip(zipcode)
          in the state calculated field expression you would show

          Code:
           usps_state_from_zip(zipcode)
          That way anytime the zipcode is changed the calculated field expression would lookup the city and the state and enter them in the appropriate fields on any form or browse connected to this table.

          However, if you have a form or a browse and the zipcode reflects a city that is not the one you want but is located in that zip code, you would not be able to change the city since it is a calculated field.

          Just a caution.

          Tom
          Hi Tom,

          Thanks for the info, this would not work because as you stated I cant change the city, state if the zip brings up the wrong info, is their any other way I can use xbasic at the table level without using calc field?
          Kind Regards,
          Ray Roosa
          Raylin Micro, LLC.

          Comment


            #6
            Re: Usps_city_from_zip() ?

            Ray

            You could try this to see if it works for you

            In the field rules for zipcode - field event - Onwrotefield

            Code:
            dim t as p
            t=table.current()
            t.city=usps_city_from_zip(t.ZIPCODE)
            t.st=usps_state_from_zip(t.ZIPCODE)
            
            t.refresh()
            just replace the fields I have with your fields.

            This will allow you to change the name of a city if the wrong city shows up.

            The only problem with this type of field event is that it does not refresh the fields until you tab into the city and state fields. I'm sure if you played around with the form field zipcodes ondepart event, you could probably get the fields to refresh. I haven't really looked at that.

            Still leave the default for city and state as it is with the usps_city_from zip() and usps_state_from_zip(). That will enter the proper zip code into the fileds when a new record is entered.

            This might work for you.

            Tom

            Comment


              #7
              Re: Usps_city_from_zip() ?

              Originally posted by Tbaker View Post
              Ray

              You could try this to see if it works for you

              In the field rules for zipcode - field event - Onwrotefield

              Code:
              dim t as p
              t=table.current()
              t.city=usps_city_from_zip(t.ZIPCODE)
              t.st=usps_state_from_zip(t.ZIPCODE)
               
              t.refresh()
              just replace the fields I have with your fields.

              This will allow you to change the name of a city if the wrong city shows up.

              The only problem with this type of field event is that it does not refresh the fields until you tab into the city and state fields. I'm sure if you played around with the form field zipcodes ondepart event, you could probably get the fields to refresh. I haven't really looked at that.

              Still leave the default for city and state as it is with the usps_city_from zip() and usps_state_from_zip(). That will enter the proper zip code into the fileds when a new record is entered.

              This might work for you.

              Tom
              Hi Tom,

              Thank you for the script however this did not work, my code is below-

              'Sets the city and state by looking up zipcode from usps
              dim t as p
              t=table.current()
              t.billing_city=usps_city_from_zip(t.BILLING_ZIP_CODE)
              t.billing_state=usps_state_from_zip(t.BILLING_ZIP_CODE)
              t.refresh()
              'End script
              Kind Regards,
              Ray Roosa
              Raylin Micro, LLC.

              Comment


                #8
                Re: Usps_city_from_zip() ?

                Ray

                Did you put your code in the field event onwrotefield for billing_zip_code?


                I just tried it with my test db and it worked.

                Here is a zip of my test app

                Just change a zipcode on an entry and then cursor into city and then into state.

                Tom

                Comment


                  #9
                  Re: Usps_city_from_zip() ?

                  Originally posted by Tbaker View Post
                  Ray

                  Did you put your code in the field event onwrotefield for billing_zip_code?


                  I just tried it with my test db and it worked.

                  Here is a zip of my test app

                  Just change a zipcode on an entry and then cursor into city and then into state.

                  Tom
                  Tom,
                  Thank you very much for all your help in resolving my trouble, after downloading your test table I noticed I was still getting the unexspected results that I was looking for, after carful review and testing your table I noticed I still had to tab into the city and state field in order for the lookup to happen so I investigated more and noticed if I did a form refresh after tabbing out if the zipcode field all worked well. The final code is below-

                  'Code used to lookup city and state from zipcode from usps website
                  dim t as p
                  'dim frm as p
                  t=table.current()
                  t.billing_city=usps_city_from_zip(t.BILLING_ZIP_CODE)
                  t.billing_state=usps_state_from_zip(t.BILLING_ZIP_CODE)
                  t.refresh()
                  form.refresh()
                  'end script
                  Kind Regards,
                  Ray Roosa
                  Raylin Micro, LLC.

                  Comment


                    #10
                    Re: Usps_city_from_zip() ?

                    Ray

                    I did not know that from a field event in the field rules that the code

                    Code:
                     form.refresh()
                    works.

                    Or did you mean

                    Code:
                     form.refresh_fields()
                    Tom

                    Comment


                      #11
                      Re: Usps_city_from_zip() ?

                      The <form>.refresh() will work from the field rules BUT it will generate an error if there is no form open and you are just working directly in a browse. It might also cause an error if just running an xbasic routine but I don't think so because most field rules aren't triggered when tables are changed with xbasic. ALSO, just using "form.refresh()" probably won't work because "form" would first have to be defined so it points the the appropriate form.

                      If you want to make that OnWrote event handle the whole thing so you don't need to worry about creating new forms and forgetting the "refresh", you can add something like this:
                      Code:
                      IF eval_valid( "parentform.this" )
                          parentform.Refresh_Layout()
                      END IF
                      FWIW: I don't believe the "<tbl>.refresh()" is intended to do what you want in this case. The <tbl>.refresh() command is really supposed to be used to refresh the current table when other scripts/users may have changed the data while something else was going on in your script. For example, you might have a script that opens a table then displays an xdialog before doing something else. If you leave the xdialog open while you answer the phone, someone else may get in and change your record. The .refresh() will update your current session with the new data.

                      Even if it refreshed the data in your table, that doesn't necessarily mean it will refresh the form because the form is a separate object. Even if it did work, I wouldn't trust it. Anyone who has used multiple versions of A5 can tell you that just because something worked in a previous version doesn't mean it will work in the next version. When this happens it's usually because the old version allowed something that shouldn't have been allowed. (If there are any perfect programmers out there, please let me know so I can add you to my black list.)

                      Whenever possible, my preferred method for handling something like that is to close any open tables before running the xdialog then re-open the table afterward. This isn't always feasible but, when it is, it's always safe.

                      The <form_pointer>.refresh() is a different story.

                      ALSO, although all the "refresh" commands say they were originally from A5v5, be aware that some of them were earlier commands that didn't always work well in certain situations. I believe the .refresh_layout() is one of the newer commands and works in more situations. I won't guarantee that it always works but it's the first one I try now.

                      (Resynching is a whole separate and complex issue that I won't even get into here.)
                      Last edited by CALocklin; 06-01-2008, 09:24 PM.

                      Comment


                        #12
                        Re: Usps_city_from_zip() ?

                        Originally posted by CALocklin View Post
                        The <form>.refresh() will work from the field rules BUT it will generate an error if there is no form open and you are just working directly in a browse. It might also cause an error if just running an xbasic routine but I don't think so because most field rules aren't triggered when tables are changed with xbasic. ALSO, just using "form.refresh()" probably won't work because "form" would first have to be defined so it points the the appropriate form.

                        If you want to make that OnWrote event handle the whole thing so you don't need to worry about creating new forms and forgetting the "refresh", you can add something like this:
                        Code:
                        IF eval_valid( "parentform.this" )
                            parentform.Refresh_Layout()
                        END IF
                        FWIW: I don't believe the "<tbl>.refresh()" is intended to do what you want in this case. The <tbl>.refresh() command is really supposed to be used to refresh the current table when other scripts/users may have changed the data while something else was going on in your script. For example, you might have a script that opens a table then displays an xdialog before doing something else. If you leave the xdialog open while you answer the phone, someone else may get in and change your record. The .refresh() will update your current session with the new data.

                        Even if it refreshed the data in your table, that doesn't necessarily mean it will refresh the form because the form is a separate object. Even if it did work, I wouldn't trust it. Anyone who has used multiple versions of A5 can tell you that just because something worked in a previous version doesn't mean it will work in the next version. When this happens it's usually because the old version allowed something that shouldn't have been allowed. (If there are any perfect programmers out there, please let me know so I can add you to my black list.)

                        Whenever possible, my preferred method for handling something like that is to close any open tables before running the xdialog then re-open the table afterward. This isn't always feasible but, when it is, it's always safe.

                        The <form_pointer>.refresh() is a different story.

                        ALSO, although all the "refresh" commands say they were originally from A5v5, be aware that some of them were earlier commands that didn't always work well in certain situations. I believe the .refresh_layout() is one of the newer commands and works in more situations. I won't guarantee that it always works but it's the first one I try now.

                        (Resynching is a whole separate and complex issue that I won't even get into here.)
                        Hi Cal,
                        Thanks for the info, I did open a default brows after reading your post and see that my code does still work even with the default brows put I still changed my code from form.refresh() to-

                        IF eval_valid( "parentform.this" )
                        parentform.Refresh_Layout()
                        END IF
                        Kind Regards,
                        Ray Roosa
                        Raylin Micro, LLC.

                        Comment


                          #13
                          Re: Usps_city_from_zip() ?

                          Originally posted by Tbaker View Post
                          Ray

                          I did not know that from a field event in the field rules that the code

                          Code:
                           form.refresh()
                          works.

                          Or did you mean

                          Code:
                           form.refresh_fields()
                          Tom
                          Hi Tom,
                          As Cal stated form.refresh() does work and that is what I was using but based on what Cal said I changed my code to-

                          IF eval_valid( "parentform.this" )
                          parentform.Refresh_Layout()
                          END IF

                          Thanks for all your help and saving me time not having to figuring this out on my own :)
                          Kind Regards,
                          Ray Roosa
                          Raylin Micro, LLC.

                          Comment


                            #14
                            Re: Usps_city_from_zip() ?

                            Ya' learn some'n new every day. I couldn't find any reference in the Help file to using "form" that way but I did find it in the list of reserved words. Apparently it is acceptable - I just wish I new exactly what it refers to.

                            By the way, if you aren't familiar with the difference in Parentform and Topparent, check it out in the Help file. Sometimes they refer to the same thing and sometimes they don't - the difference can be significant.

                            Comment


                              #15
                              Re: Usps_city_from_zip() ?

                              Cal

                              I'm not trying to beat a dead horse since Ray has gotten his app working with your help.

                              But when I used form.refresh() in the onwrotefield for zipcode and then opened the form, I get an error message (see attached thumbnail).

                              I also attached a thumbnail of the onwrotefield event.

                              That is why I didn't think that would work and suggested form.refresh_fields() which does work.

                              I guess this is just to enhance my knowledge.

                              Thanks

                              Tom Baker

                              Comment

                              Working...
                              X