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

Adding New Records to Child dbf

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

    Adding New Records to Child dbf

    I am posting some code that perhaps someone out there can help me with.

    I have a parent/child database that handles inventory labels. When these labels are purchased they need to be added to the inventory and then used later on.

    I want the user to select a record in the parent, then use the following script on a button which will add the records to the child database.

    The script is as follows (sorry for the jumble):

    'Date Created: 27-Dec-2002 06:16:20 PM
    'Last Updated: 28-Dec-2002 01:12:31 AM
    'Created By :
    'Updated By :
    'Displays a message box (style:'OK Button', image: 'Attention symbol', id: 'Msg1').
    DIM SHARED Msg1_result as N
    DIM SHARED Msg1_OK_Button as L
    Msg1_OK_Button = .F.

    title_var = "Enter new Asset Labels"
    message_text_var = vartags+\" additional labels to this main category of the database. Is this correct?\"")
    Msg3_result=ui_msg_box(title_var,message_text_var,UI_OK_CANCEL+ UI_FIRST_BUTTON_DEFAULT+ UI_INFORMATION_SYMBOL)
    'Test to see which button on the message box was pressed....
    SELECT
    CASE Msg3_result = UI_OK_SELECTED
    Msg3_OK_Button= .t.
    CASE Msg3_result = UI_CANCEL_SELECTED
    Msg3_CANCEL_Button= .t.
    END SELECT

    dim lastrec as c

    t=table.current(1)
    c=table.current(2)
    vartest=t.mainno
    'vartest.refresh()
    c.fetch_last()

    if msg3_ok_button = .t. then
    lastrec=c.subno
    dim counter as n
    'dim subcount as n
    dim subby1 as c
    counter=1
    'subby1=padl(alltrim(str(val(c.subno)+1)),4,"0")
    'subcount=alltrim(str(val(c.subno)+counter))

    while countervartags)
    subby1=padl(alltrim(str(val(lastrec)+counter)),4,"0")
    c.enter_begin()
    c.MAINNO = t.mainno
    c.SUBNO = subby1
    c.enter_end(.t.)
    counter=counter+1
    end while
    end if

    The problem I am getting is that when the script is executed, the computer says that you can't do "c.fetch_last" in Enter or change mode.

    Can anyone tell me where I can correct this?

    Thanks,

    Charlie

    #2
    RE: Adding New Records to Child dbf

    sometimes you have to check to see if the table is in change or enter mode. Try something like this
    t=table.current(1)
    c=table.current(2)
    vartest=t.mainno
    'vartest.refresh()
    if c.mode_get()=0 then 'I do not remember if it is =0 or >0
    parentform.commit()
    end if
    c.fetch_last()

    Comment


      #3
      RE: Adding New Records to Child dbf

      I would also look into *why* the table is in enter mode. Unless I am overlooking something your script does not do so. Hence something prior to the script must be.

      Bill
      Bill Hanigsberg

      Comment


        #4
        RE: Adding New Records to Child dbf

        Charles,
        I had a similar problem. I wanted to use a script to add payment information to a child table. I had a field from the table on the form which I filled in before clicking the button. However, filling in the one field directly put the table in enter mode and then I couldn't put it in enter mode in the script. I solved it by putting the value into a variable and then putting the value in the table via the script. Anything similar happening to you?

        Comment


          #5
          RE: Adding New Records to Child dbf

          Newbie question here...

          I understand now that a form has 3 basic modes View, Change, Enter, (with some codes for Browse and Query too, if I remember), and that works well..

          Although I feel it could be emphasized a bit more in docs, how to know the mode, place current mode on the screen etc.. it is such a basic functionality issue of a form

          =================================

          So it seems that in this PC/Alpha/.dbf environment, the table also has a "Mode" ?

          This is curious to me, coming from an ISAM mini-computer environment, where the only such aspect of a table, afiak, would be what records are currently "open" (ie. read but not updated or released)and those records are "locked" ... (more sophisticated OS/language environments put more record locking gestalt into the op system, even allowing field level locking, I believe)....

          In that environment, you simply return the open record, or you append a new record, there is no issue of modes in terms of the open table (aka..file)

          ======================================
          Question..

          Why would such table modes exist?
          What purpose? What need ?

          And if they do run similar in importance and action to form modes, perhaps they are also not given their full due in examples and explanations in the docs ?

          Especially if it is something the programmer has to be aware of to be sure his commits work right.

          ========================================





          Comment


            #6
            RE: Adding New Records to Child dbf

            If the child table is empty when you open the form, the table is automatically put into enter mode. Try this with a browse on a completely empty table and you'll see what I mean--the table goes into enter mode right away.

            There are a couple of ways you can deal with this:
            1) If you are never going to enter records into the child table from the form, you can make the browse for the child table read-only. That should keep the browse from going into enter mode.
            2) What is probably a more secure solution is to do the Xbasic entry into a new pointer. That is, instead of
            c=table.current(2)
            write
            c=table.open(table.current(2).name_get())
            Make sure when you do the data entry on the new instance of the child table that you explicitly make an entry into the linking field.
            Also, at the end of data entry, issue a
            topparent.resynch()
            so that the newly entered child records will appear.

            There are other ways of dealing with this issue but they are all variations on one or the other of the above approaches.

            Comment


              #7
              RE: Adding New Records to Child dbf

              Steven:
              Question..

              Why would such table modes exist?
              What purpose? What need ?

              ===============================================

              Tom:
              Lift your sights a bit higher. Alpha Five presents a high level interface to the user. We do not have to manually lock a record when we want to commit a change, for example. Alpha Five handles all of the messy tedious network details for us. In exchange, we must adhere to its interface requirements. One of those is that we cannot initiate a change to the table while the current instance of the table has a change or enter pending already. Xbasic's commands to get the current mode of the table enable the designer to put together a script that can take alternative branches depending upon whether a change or enter has already started in the current instance of the table. Peruse the docs on table.change_begin() and table.enter_begin() for more details.

              -- tom

              Comment


                #8
                RE: Adding New Records to Child dbf

                Doc,

                You're the best! That was exactly the mistake I made. I looked for a couple of hours, then gave up and wrote the post.

                As way of some additional information, I also tried setting up the child field as auto-increment, thinking that if I added records, they would add in correctly. Instead what I got was the child finding the last number in that field and auto-incrementing from there.

                Another question. In order to increment my character field I had to write and use the expression:

                subby1=padl(alltrim(str(val(lastrec)+counter)),4,"0")

                however, I notice that auto-increment does this automatically when it is turned on. Is there another expression out there that I am missing?

                Thanks again and thanks to all!

                Charlie

                Comment


                  #9
                  RE: Adding New Records to Child dbf

                  Sorry , maybe I spoke a bit too soon. What I need to get from the line c.fetch_last() is the last record in the child corresponding to the parent, not the actual last record in the child.

                  What I keep getting is the last child record. The script works well from there, adding the necessary records and adding the link field "Mainno". But the "Subno" field is wrong.

                  How do I stay within the set, so that when the fetch_last is requested I get the last child record? Do I need to create a query or filter? I thought that as long as I was in the set format this would work.

                  Thanks,

                  Charlie

                  Comment


                    #10
                    RE: Adding New Records to Child dbf

                    OK, I think I figured it out.

                    In order for the set to work and the lookup of the last field via fetch to work, the expression for the child needs to be: c=table.get("child_name").

                    I ALWAYS defer to the Doc, so if I'm doing something wrong, please let me know, but it seems to be working now, even when there are no records existing in the child dbf.

                    Thanks,

                    Charlie

                    PS: Maybe we should post a cleaned up copy of this code for other?

                    Comment


                      #11
                      RE: Adding New Records to Child dbf

                      Tom:
                      Lift your sights a bit higher. Alpha Five presents a high level interface to the user. We do not have to manually lock a record when we want to commit a change, for example.

                      Steven
                      Hi Tom, Yes I know that in Windows there is no table or record control, everything that *could* be an operating system function must be handled by Alpha, including record locking..

                      Tom
                      Alpha Five handles all of the messy tedious network details for us.

                      Steven
                      Essentially Alpha acts as a mini-operating system, which is true with maybe all PC languages, a necessity of the age ..

                      Tom
                      In exchange, we must adhere to its interface requirements. One of those is that we cannot initiate a change to the table while the current instance of the table has a change or enter pending already.

                      Steven
                      Is Alpha is unable to handle this on a record level ?
                      If Alpha was working on a record level, it would not be concerned with multiple updates to the table, if they are working on different records. (Alpha would still have to decide what to do on that level however, deep topic..)
                      Ergo there would be much less concern for explicit programmer statements..

                      Tom
                      Xbasic's commands to get the current mode of the table enable the designer to put together a script that can take alternative branches depending upon whether a change or enter has already started in the current instance of the table. Peruse the docs on table.change_begin() and table.enter_begin() for more details.

                      Steven
                      Ok.. I will ..
                      However so far I really don't see how the mode really is functionally the issue ..

                      E.G. an "Entry" never effects an update anyway, there should be a capability for 100 Entrys to be done without affecting what happens with a record or two that are held for update... the real locking issue essentially occurs only in multiple updates...

                      Will research...

                      Comment

                      Working...
                      X