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

Best practice record lookup or query?

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

    Best practice record lookup or query?

    Hi all,

    I'm after a bit of best practice advice...

    I have a set which is 1 to many (Header/Items)

    On the main form I maintain the header fields and all works ok.

    Also on this form I have a variable field for a barcode which is a unique identifier to the items. What I'd like to be able to do is when I scan a barcode is do a lookup/filter/query and open an "Item" form with the form waiting for input from the user in the correct mode.

    The correct mode is determined as follows;
    - "enter new item" mode if the barcode was not found.
    - "amend existing item" mode if the barcode was found.

    What's the best practice way to locate the required record in this type of scenario?


    Thanks in advance for any help...
    Regards,
    Darren Farmer
    ________________________
    Alpha5V8 Enterprise
    Windows XP Professional
    AMD Turion 64 x2/Athlon 64

    #2
    Re: Best practice record lookup or query?

    Darren,
    I "probe" tables alot with branchpoint if-then or Select-case statements. I use a5_get_records_in_query() because I generally have local variables and varying and somewhat compound/complex filter expressions needed for the query. It would generally look like this for you:

    Code:
    dim vbarcodescanned as C
    
    if a5_get_records_in_query(tablename,"barcodefield = "+s_quote(vbarcodescanned ) = 0 then
      >> open form in entry mode
    else
      >> open form filtered 
    end if
    Because this a very specific event with a simple filter expression, you could set up and index for the barcode field and use dbcount() instead of A5griq. Look into it in the documentation.
    Mike W
    __________________________
    "I rebel in at least small things to express to the world that I have not completely surrendered"

    Comment


      #3
      Re: Best practice record lookup or query?

      Thanks Mike - I'll look into this technique...
      Regards,
      Darren Farmer
      ________________________
      Alpha5V8 Enterprise
      Windows XP Professional
      AMD Turion 64 x2/Athlon 64

      Comment


        #4
        Re: Best practice record lookup or query?

        Mike,

        When I've determined what mode to open the form in (using the a5_get...), what would be the most efficient way of getting to the record represented by the barcode? Would it be a query or a filter (or other)? Also, what event would you use on the form that is being opened to locate the record to be amended - OnActivate?

        Thanks...
        Regards,
        Darren Farmer
        ________________________
        Alpha5V8 Enterprise
        Windows XP Professional
        AMD Turion 64 x2/Athlon 64

        Comment


          #5
          Re: Best practice record lookup or query?

          I think using an indexed find by key or using a query that can use a permanent index via lightning query optimization will be pretty much six of one or half a dozen of the other. I would not embed a filter into the called form's layout.

          I would not use any events on the called form to locate the record. Instead I would open the form hidden, do the find or query, and then show the form. All work would be done from the script that opens (loads) the called form.

          Comment


            #6
            Re: Best practice record lookup or query?

            Hi,

            Ok, I'm a bit stuck with this and I've got a bad case of Help file overload

            I'm still trying to load a form in the correct mode with the correct record displayed on the form once it's displayed.

            In the following code, ".fetch_find()" is locating the correct record number and the Quick_Prod_Variants form is being displayed, but it doesn't display the correct record. It actually displays the 1st record in the product_variants table and not the one that was found in the index.

            Here's the code I have in the OnChange event of a field on the parent form and I'm trying to open the Child form with the record that was located by the "...fetch_find" - any ideas?

            Thanks in advance...

            DIM Shared varP_Quick_Prod_Variants as P
            DIM Shared varN_recno as N
            DIM varC_table_name as C
            DIM varC_index_name as C

            'Sep-up constants
            varC_table_name = "product_variants"
            varC_index_name = "Pv_Barcode"

            'Open table
            varP_Quick_Prod_Variants = table.open(varC_table_name,file_rw_shared)

            'Select the required index to use
            varP_Quick_Prod_Variants.index_primary_put(varC_index_name)

            'Get the record number of the required record
            varN_recno = varP_Quick_Prod_Variants.fetch_find(v_barcode_int)

            'Decide what mode to open the form in
            if (varN_recno > 0) then
            'Record exists
            form.load("Quick_Prod_Variants2")
            varP_Quick_Prod_Variants.fetch_goto(varN_recno)
            varP_Quick_Prod_Variants.change_begin()
            Quick_Prod_Variants.show()
            Quick_Prod_Variants.activate()
            else
            'Record doesn't exist
            form.load("Quick_Prod_Variants")
            varP_Quick_Prod_Variants.enter_begin()
            Quick_Prod_Variants.show()
            Quick_Prod_Variants.activate()
            end if

            END
            Regards,
            Darren Farmer
            ________________________
            Alpha5V8 Enterprise
            Windows XP Professional
            AMD Turion 64 x2/Athlon 64

            Comment


              #7
              Re: Best practice record lookup or query?

              Darren,

              This sort of popped out at me--could be the problem?? The "2" indicates this is the third instance of this form but you have only opened one---makes me think you have copied some of this script from Action Scripting and when you did (if you did!) it included the "2" in the script (and rightly so if 3 forms were open). You also have a "show()" function but don't see where you opened the form as hidden....


              Code:
              'Decide what mode to open the form in
              if (varN_recno > 0) then
              'Record exists
              form.load("Quick_Prod_Variants[COLOR="Red"]2[/COLOR]")
              varP_Quick_Prod_Variants.fetch_goto(varN_recno)
              Last edited by MikeC; 10-16-2007, 08:52 PM.
              Mike
              __________________________________________
              It is only when we forget all our learning that we begin to know.
              It's not what you look at that matters, it's what you see.
              Henry David Thoreau
              __________________________________________



              Comment


                #8
                Re: Best practice record lookup or query?

                Thanks for replying Mike... sorry, that's my fault, that was just a test I was doing with a simplified version of the child form, which came up with the same results - ie; it still displayed the 1st record in the child table.

                Does it look to you like I'm on the right track with what I'm trying to do?

                Also, not sure if it makes a difference, but the parent form is based on a parent/child SET and the child form being opened by the OnChange event code is also based on the same SET.
                Regards,
                Darren Farmer
                ________________________
                Alpha5V8 Enterprise
                Windows XP Professional
                AMD Turion 64 x2/Athlon 64

                Comment


                  #9
                  Re: Best practice record lookup or query?

                  Originally posted by daz_racing View Post
                  'Decide what mode to open the form in
                  if (varN_recno > 0) then
                  'Record exists
                  form.load("Quick_Prod_Variants2")
                  varP_Quick_Prod_Variants.fetch_goto(varN_recno)
                  varP_Quick_Prod_Variants.change_begin()

                  Quick_Prod_Variants.show()
                  Quick_Prod_Variants.activate()

                  else
                  'Record doesn't exist
                  form.load("Quick_Prod_Variants")
                  varP_Quick_Prod_Variants.enter_begin()
                  Quick_Prod_Variants.show()
                  Quick_Prod_Variants.activate()

                  end if

                  END

                  Darren,

                  You are mixing table pointer methods and form methods The form that you have opened has a different session to the table you have opened. and so is not seeing what is happening there. Keep every thing at the form level in this case.
                  Code:
                   'Decide what mode to open the form in
                  if (varN_recno > 0) then
                      'Record exists
                      'No need to but form into change mode.
                      'That happens when you start editing a field.
                      [COLOR=Black]frmP = form.load("Quick_Prod_Variants")
                      frmP.index_set([/COLOR]varC_index_name[COLOR=Black])
                      frmP.find([/COLOR]v_barcode_int[COLOR=Black])
                      [/COLOR][COLOR=Black]frmP.show()
                      frmP.activate()[/COLOR]
                  else
                      'Record doesn't exist[COLOR=Black]
                      frmP = f[/COLOR][COLOR=Black]orm.load("Quick_Prod_Variants")
                      frmP.new_Record()
                      [/COLOR][COLOR=Black]frmP.show()
                      frmP.activate()[/COLOR]
                  end if
                  Since you have an index available you could replace this
                  Code:
                  DIM Shared varP_Quick_Prod_Variants as P
                  DIM Shared varN_recno as N
                  DIM varC_table_name as C
                  DIM varC_index_name as C
                  
                  'Sep-up constants
                  varC_table_name = "product_variants"
                  varC_index_name = "Pv_Barcode"
                  
                  'Open table
                  varP_Quick_Prod_Variants = table.open(varC_table_name,file_rw_shared)
                  
                  'Select the required index to use
                  varP_Quick_Prod_Variants.index_primary_put(varC_index_name)
                  
                  'Get the record number of the required record
                  varN_recno = varP_Quick_Prod_Variants.fetch_find(v_barcode_int)
                  with
                  Code:
                   DIM Shared varP_Quick_Prod_Variants as P
                  DIM Shared varN_recno as N
                  DIM varC_table_name as C
                  DIM varC_index_name as C
                  
                  'Sep-up constants
                  varC_table_name = "product_variants"
                  varC_index_name = "Pv_Barcode"
                  
                  'Decide what mode to open the form in
                  if exist(v_barcode_int,varC_table_name,varC_index_name) then
                  etc......
                  Tim Kiebert
                  Eagle Creek Citrus
                  A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

                  Comment


                    #10
                    Re: Best practice record lookup or query?

                    awww..thank you Tim--just got back on and was checking out some of the same things you just pointed out---but am glad you did as although I can do most things myself I still many times have a hard time explaining them to others.
                    Mike
                    __________________________________________
                    It is only when we forget all our learning that we begin to know.
                    It's not what you look at that matters, it's what you see.
                    Henry David Thoreau
                    __________________________________________



                    Comment


                      #11
                      Re: Best practice record lookup or query?

                      Originally posted by MikeC View Post
                      awww..thank you Tim--just got back on and was checking out some of the same things you just pointed out---but am glad you did as although I can do most things myself I still many times have a hard time explaining them to others.
                      As we say down here "No worries, mate"
                      Tim Kiebert
                      Eagle Creek Citrus
                      A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

                      Comment


                        #12
                        Re: Best practice record lookup or query?

                        mike, tim,
                        at least one of you (that would be the one this side of GMT) needs to go to bed..oh me too I guess...
                        Mike W
                        __________________________
                        "I rebel in at least small things to express to the world that I have not completely surrendered"

                        Comment


                          #13
                          Re: Best practice record lookup or query?

                          Thanks guys... I'll try it out ASAP...

                          ...and looking at my posting time, I need to get some sleep as well! ;)
                          Regards,
                          Darren Farmer
                          ________________________
                          Alpha5V8 Enterprise
                          Windows XP Professional
                          AMD Turion 64 x2/Athlon 64

                          Comment

                          Working...
                          X