Editing data from database in textbox which are taken from subform

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • galvanize
    New Member
    • Jul 2013
    • 11

    Editing data from database in textbox which are taken from subform

    In my form I have a subform, which displays A, B, C. Then information C is displayed in textbox. User should have a possibility to modify this data in order to modify data in database.

    I am able to display information C in text box based on this subform. However it is uneditable, although property of enabled is yes and locked is no.

    It seems to me, that it is impossible to edit data because it is taken not directly from database but from sub form, so I make special query which takes data directly from database however I lose an event which is based on selecting proper record from subform (there is only onEnter and onExit events)

    Is it possible to make such things?

    Thank you for any advices!

    [ModEdit>>z{Merg ed post #2 by OP as follows}]

    "I am able to display information C in text box based on this subform. However it is uneditable, although property of enabled is yes and locked is no."

    I received a message "Control can't be edited; it's bound to the expression".
    Last edited by zmbd; Jul 11 '13, 07:14 PM. Reason: [z{Second post is continuation of information in the first post}]
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    t seems to me, that it is impossible to edit data because it is taken not directly from database but from sub form,
    It is more likely that your recordset for the subform is not from an editable source, at least for that field.

    Please read thru: > Before Posting (VBA or SQL) Code

    Then post your SQL for the subform.

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      I suspect they are using a textbox bound to an expression related to the subform and attempting to edit that bound control rather than the source data.

      Comment

      • galvanize
        New Member
        • Jul 2013
        • 11

        #4
        Thank You for a replay.

        So, data in subfrom are editable.

        SQL Code (no VBA, written in Record Source) for subPurpose:
        Code:
        SELECT qryPurpose.[ID Job Position]
           ,qryPurpose.Discipline, qryPurpose.Position
           ,qryPurpose.Purpose 
        FROM qryPurpose;
        or without query it can be written:
        Code:
        SELECT [Job Positions].[ID Job Position]
           ,Positions.Position, Disciplines.Discipline
           ,[Job Positions].Purpose
        FROM Positions
           INNER JOIN (Disciplines 
              INNER JOIN [Job Positions]
                 ON Disciplines.[ID Discipline] 
                    = [Job Positions].[ID Discipline])
              ON Positions.[ID Position] 
                 = [Job Positions].[ID Position];
        and txtPurpose which is a text box:
        Code:
        Control Source: 
           =[subPurpose]![Purpose]
        Last edited by zmbd; Jul 11 '13, 05:41 PM. Reason: [z{stepped SQl for better read}]

        Comment

        • galvanize
          New Member
          • Jul 2013
          • 11

          #5
          Rabbit,

          How can I get data from database through text box, depending on selected position from subform and then have a possibility to modify them?

          Comment

          • zmbd
            Recognized Expert Moderator Expert
            • Mar 2012
            • 5501

            #6
            I'm with Rabbit on this,
            Where exactly is this control "C" located in your forms.

            Comment

            • galvanize
              New Member
              • Jul 2013
              • 11

              #7
              There is a simple form with text box in Detail section and subform in footer section.

              Comment

              • zmbd
                Recognized Expert Moderator Expert
                • Mar 2012
                • 5501

                #8
                Please be specific:

                The text box showing the information "C" is located where, main form, sub form 1, or some other form or location.

                Comment

                • galvanize
                  New Member
                  • Jul 2013
                  • 11

                  #9
                  Thank You for patience.
                  The text box showing the information "C" is located in main form in Detail Section.
                  The sub form is located in the same main form in Footer Section. It takes data from query, but taking data directly from table makes no difference.

                  All I want is to modify information C based on selected A. My idea was to make a subform, where user can select A and because of length of information and aesthetic point of way display info C not in the same subform as A but in seperate Text box. Everything is going well apart the fact that I can't modify info C in text box.

                  Comment

                  • galvanize
                    New Member
                    • Jul 2013
                    • 11

                    #10
                    It is possible to make another sub form with info C depending on sub form with info A, which can editable. So it will be probably the best idea, I just create a nice looking another sub form.

                    Comment

                    • zmbd
                      Recognized Expert Moderator Expert
                      • Mar 2012
                      • 5501

                      #11
                      IMHO, You are making things too complex.

                      Rabbit hit the nail on the head (has the correct answer) as to why you can not edit the information directly in the textbox-C on the mainform.

                      You have a few options; however, none of them as easy as letting the user modify the data in the subform which is bound to the query. Otherwise you are stuck with a ton of vba.

                      With your current set-up (and I'm guessing)
                      Take txt-C and unbind it, remove the control source.
                      In your subform, in the on_current event, you will copy the current code to the txt-c,
                      In the after update event of txt-c you will need to check to see if the value in the subform matches the value in txt-c - if not then save the value in txt-c to the current record in subform.
                      Your Txt-A will need some simular code to work to alter what is in C. Clear as mud (Z-Z)... ?

                      Comment

                      • galvanize
                        New Member
                        • Jul 2013
                        • 11

                        #12
                        Yep, everything is working now as I wanted!

                        I also used suggestions from this topic:


                        I wrote about this problem on a few forum, but You gave me right answer.

                        Thank You for support and solution!

                        Comment

                        Working...