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

How to Add Records to Dynamic Look-up

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

    How to Add Records to Dynamic Look-up

    I have a field set to Look-up and did not check the User Must Select From List check box there by allowing the user to enter a value that is not stored in the Look-up table. The look-up definition also adds data to the corresponding fields once the value is selected.

    My question: Is it possible to add the new record or the new data to the Look-up table once it is entered in the table in question? If so how? I know I could go to the look-up table and re-enter it but I'm hoping there's a way to copy the data to the look-up table to avoid redundancy.

    Thanks much,

    kenn
    TYVM :) kenn

    Knowing what you can achieve will not become reality until you imagine and explore.

    #2
    Re: How to Add Records to Dynamic Look-up

    I'd have a look at this but just can't find the same stuff sometimes... like now. Is this using a Grid with a DBF table? I can't seem to find the option "User Must Select From List". Point me in the right direction.

    Comment


      #3
      Re: How to Add Records to Dynamic Look-up

      DavidK -
      the UserMustSelect from List option is within the dialog window for:
      Grid.Field.Lookup.EditCombo
      and/or
      Grid.Field.Lookup.AutoSuggest


      Kenn
      if you are using SQL, you can find out which are the naughty records that are in the table and not in the lookup table, and then add them to the lookup table (and set a relationship between the two fields, so it can't happen again); select Fieldx from TableBlah where Fieldx not in (select FieldY from LookupTable)

      to facilitate adding the naughty records to the lookup table:
      Select 'insert into Lookup Table (FieldY) Select '+Fieldx
      from TableBlah
      where Fieldx not in (select FieldY from LookupTable)

      that will give you a result set which is the code for doing the inserts

      then you can do an update to fill in the other fields as needed
      MSQL since 2010
      A5V11 since Feb 2012

      Comment


        #4
        Re: How to Add Records to Dynamic Look-up

        Thanks Marion... I was looking at a fieldtype of Dropdownbox... no wonder...

        Comment


          #5
          Re: How to Add Records to Dynamic Look-up

          Hello David and Marion,

          It used to be that it wasn't hard to explain where things are and how to get to them. Now, there are so many properties, it almost takes a GPS to find them. Once something really cool is found, I can't remember where I found it a half hour later. Hopefully, this will be a better explanation. In the Detail View part of the grid, click on the Properties and go to the Lookup section' check the Lookup box and then choose Auto Suggest List in the Lookup Type. Next, open the Lookup Definition and you'll see the Auto Suggest Field settings window. The 4th setting from the top is the User Must Select From List check box. In my case, the user must have the ability to enter data if there is not a matching value in the Lookup table.

          What I need, is the ability to add the new value to the Lookup table w/o having to go to the Lookup table and re-enter it.

          Also, the Lookup table is a dbf table. In the Lookup Definition, there is nothing which would allow me to add the fields to the look-up table.

          Thanks

          kenn
          TYVM :) kenn

          Knowing what you can achieve will not become reality until you imagine and explore.

          Comment


            #6
            Re: How to Add Records to Dynamic Look-up

            I thought the Javascript AfterSelect event in the Lookup Definition might help out here... but, alas, it does not. This event only fires when an item is selected from the dropdown list.

            So, I think you'd have to use the Field, Javascript, OnChange event. I put an Ajaxcallback in this event. I'm using a MYSQL table for the Lookup table.
            Overall, try to find the Item being added... if it's there then all is ok. If it's not there, then add it.

            EDIT: Just read your post, Ken, so you'll need to change stuff a bit for the DBF table.

            Code:
            var rowNum = {Grid.RowNumber};
            {grid.Object}.ajaxCallback('G',rowNum,'UpdateLookupTable');
            And, the Xbasic function is...

            Code:
            function UpdateLookupTable as c (e as p)
            'This function will handle the Ajax callback. 
            'It must return a string of Javscript commands that will be executed in the Browser.	
            
            'The 'e' object contains all of the data that is submitted in the Ajax callback.
            
            dim cn as sql::connection
            dim args as sql::arguments
            dim sqlStmt as c
            dim rs as sql::resultset
            
            flag = cn.open("::Name::YOURNAMEDCONNECTION","YOURSQLACCOUNT","YOURPASSWORD")
            
            'Is the Item selected in the Lookup table?
            dim sqlStmt as c
            sqlStmt = "SELECT ProdName FROM tblProducts WHERE ProdName = :argsItem"
            
            args.add("argsItem",e._currentRowDataNew.Account)
            flag = cn.execute(sqlStmt,args)
            
            rs = cn.resultset
            flag = rs.nextRow()
            if flag then
            	'the item selected was already there, so don't do anything
            else
            	'the item is not in the lookup table, so add it.
            	sqlStmt = "INSERT INTO tblProducts (ProdId,ProdName) VALUES (999,'" + e._currentRowDataNew.Account + "')"
            	flag = cn.execute(sqlStmt)
            end if
            
            UpdateLookupTable = "alert('You inserted a value of: " + js_escape(e._currentRowDataNew.Account) + "');"
            
            end function

            Comment


              #7
              Re: How to Add Records to Dynamic Look-up

              Hi David,

              I'm not sure if the changes I made are correct and there is more to change but I don't know what to change them to. My comments are in caps except for what you capped.

              Thank you for your help.

              kenn

              This is what I did:

              function UpdateLookupTable as c (e as p)
              'This function will handle the Ajax callback.
              'It must return a string of Javscript commands that will be executed in the Browser.

              'The 'e' object contains all of the data that is submitted in the Ajax callback.

              dim cn as dbf::connection ‘DON’T KNOW IF ‘CONNECTION’ IS NEEDED ?
              dim args as dbf::arguments
              dim dbfStmt as c
              dim rs as dbf::resultset

              flag = cn.open("::Name::YOURNAMEDCONNECTION","YOURSQLACCOUNT","YOURPASSWORD") ‘IS SIMILAR NEEDED? IF SO, WHAT?

              'Is the Item selected in the Lookup table?
              dim dbfStmt as c
              dbfStmt = "SELECT Employer FROM tblt_Employers WHERE Employer = :argsItem"

              args.add("argsItem",e._currentRowDataNew.Account) ‘DON’T KNOW WHAT NewAccount means?
              flag = cn.execute(sqlStmt,args)

              rs = cn.resultset
              flag = rs.nextRow()
              if flag then
              'the item selected was already there, so don't do anything
              else
              'the item is not in the lookup table, so add it.
              dbfStmt = "INSERT INTO tblt_Employers (Employer) VALUES (999,'" + e._currentRowDataNew.Account + "')"
              flag = cn.execute(dbfStmt)
              end if

              UpdateLookupTable = "alert('You inserted a value of: " + js_escape(e._currentRowDataNew.Account) + "');"

              end function
              TYVM :) kenn

              Knowing what you can achieve will not become reality until you imagine and explore.

              Comment


                #8
                Re: How to Add Records to Dynamic Look-up

                For DBF tables it's all different. You'll need to adjust for your field names, but this should get you close.

                Code:
                'The following code is for DBF Tables
                'debug(1)
                dim tbl as p
                tbl = table.open("accountlookup")
                query.filter = "acctname = '" + e._currentRowDataNew.Account + "'"
                indx = tbl.query_create()
                records = indx.records_get()
                If records = 0 then
                	'Add the item input because it's not in the table
                	tbl.enter_begin(.T.)
                	tbl.ACCTID = 888
                        tbl.ACCTNAME = e._currentRowDataNew.Account
                	tbl.enter_end(.T.)
                	UpdateLookupTable = "alert('Item input added to lookup table');"	
                end if
                	
                tbl.close()

                Comment

                Working...
                X