Update an unbound form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • troy_lee@comcast.net

    #1

    Update an unbound form

    I have an unbound form. I have an Add New procedure that saves a new
    record to the database. What is the best way to update an existing
    record? In other words, clicking my "Submit record" button creates
    another new instance of the record when all I want is to update a
    field or two and save over the existing record.

    Thanks in advance.

    Troy
  • Allen Browne

    #2
    Re: Update an unbound form

    Why are you using an unbound form?

    It is possible to create an interface where you provide a mechanism for the
    user to select from the choices that define an existing record, and then
    populate your unbound boxes with the values from those records, and then
    keep track of whether any of them changed, and provide some way for the user
    to instuct you to commit or cancel the changes, and then execute an Update
    query to modify the existing record.

    But WHY? When a bound form does exactly that for you, without any coding?
    It's also possible to use paper index cards instead of a database, and it
    probably makes as much sense.

    --
    Allen Browne - Microsoft MVP. Perth, Western Australia
    Tips for Access users - http://allenbrowne.com/tips.html
    Reply to group, rather than allenbrowne at mvps dot org.

    <troy_lee@comca st.netwrote in message
    news:3ac909b2-3169-42bc-bb01-00520faa199d@y3 8g2000hsy.googl egroups.com...
    >I have an unbound form. I have an Add New procedure that saves a new
    record to the database. What is the best way to update an existing
    record? In other words, clicking my "Submit record" button creates
    another new instance of the record when all I want is to update a
    field or two and save over the existing record.
    >
    Thanks in advance.
    >
    Troy

    Comment

    • Keith Wilby

      #3
      Re: Update an unbound form

      <troy_lee@comca st.netwrote in message
      news:3ac909b2-3169-42bc-bb01-00520faa199d@y3 8g2000hsy.googl egroups.com...
      >I have an unbound form. I have an Add New procedure that saves a new
      record to the database. What is the best way to update an existing
      record? In other words, clicking my "Submit record" button creates
      another new instance of the record when all I want is to update a
      field or two and save over the existing record.
      >
      Don't use "AddNew". You'll probably have something like this currently:

      With rs
      .AddNew
      ![MyField] = "Whatever"
      .Update
      End with

      Just lose the ".AddNew" command. Be sure you're pointing at the correct
      record first of course!

      Keith.


      Comment

      • Fred Zuckerman

        #4
        Re: Update an unbound form

        "Keith Wilby" <here@there.com wrote in message
        news:48da4d0f_1 @glkas0286.gree nlnk.net...
        <troy_lee@comca st.netwrote in message
        news:3ac909b2-3169-42bc-bb01-00520faa199d@y3 8g2000hsy.googl egroups.com...
        >>I have an unbound form. I have an Add New procedure that saves a new
        >record to the database. What is the best way to update an existing
        >record? In other words, clicking my "Submit record" button creates
        >another new instance of the record when all I want is to update a
        >field or two and save over the existing record.
        >>
        >
        Don't use "AddNew". You'll probably have something like this currently:
        >
        With rs
        .AddNew
        ![MyField] = "Whatever"
        .Update
        End with
        >
        Just lose the ".AddNew" command. Be sure you're pointing at the correct
        record first of course!
        >
        Keith.
        www.keithwilby.com
        Actually, I think you'll want to replace .AddNew with .Edit
        Fred Zuckerman


        Comment

        • Keith Wilby

          #5
          Re: Update an unbound form

          "Fred Zuckerman" <ZuckermanF@sbc global.netwrote in message
          news:OwsCk.1218 $as4.61@nlpi069 .nbdc.sbc.com.. .
          >
          Actually, I think you'll want to replace .AddNew with .Edit
          Fred Zuckerman
          >
          >
          Whoops! Yes, thanks Fred. Although I do take Allen's point about using a
          bound form.

          Regards,
          Keith.

          Comment

          • troy_lee@comcast.net

            #6
            Re: Update an unbound form

            I agree with Allen about bound forms. I have also read Allen's
            tutorial on locking bound forms. My problem with a bound form in this
            case is this:

            Form B is being opened from Form A, a bound form. There is one field
            on Form A whose value is assigned to a field on Form B. This field is
            the PK from Form A's table. I am using this field as an index for Form
            B's table, but it is not part of a composite key (referential
            integrity is not that important for this). This field is the link for
            the one to many relationship from Table A to Table B.

            My question is how can I bind this field to Form B if I pass its value
            from Form A? I want to pass it because I do not want the user to
            manually input this field. But, if it is unbound it can't provide its
            value to Form B's underlying table without VBA code. I know I'm
            missing something here, but I can't quite clarify what it is.

            Hope this makes sense.

            Thanks in advance.

            Troy Lee

            Comment

            • Allen Browne

              #7
              Re: Update an unbound form

              Pass the value in OpenArgs, e.g.:
              DoCmd.OpenForm "B", DataMode:=acFor mAdd, OpenArgs:=Me.[ID]

              Then use the Load event of form B to assign the value to the field if it was
              passed in OpenArgs and the form is at a new record. That should work even if
              you open B in dialog mode.

              --
              Allen Browne - Microsoft MVP. Perth, Western Australia
              Tips for Access users - http://allenbrowne.com/tips.html
              Reply to group, rather than allenbrowne at mvps dot org.

              <troy_lee@comca st.netwrote in message
              news:3fb81db6-a29d-4e0c-956b-2b22fbb8be4f@p2 5g2000hsf.googl egroups.com...
              >I agree with Allen about bound forms. I have also read Allen's
              tutorial on locking bound forms. My problem with a bound form in this
              case is this:
              >
              Form B is being opened from Form A, a bound form. There is one field
              on Form A whose value is assigned to a field on Form B. This field is
              the PK from Form A's table. I am using this field as an index for Form
              B's table, but it is not part of a composite key (referential
              integrity is not that important for this). This field is the link for
              the one to many relationship from Table A to Table B.
              >
              My question is how can I bind this field to Form B if I pass its value
              from Form A? I want to pass it because I do not want the user to
              manually input this field. But, if it is unbound it can't provide its
              value to Form B's underlying table without VBA code. I know I'm
              missing something here, but I can't quite clarify what it is.
              >
              Hope this makes sense.
              >
              Thanks in advance.
              >
              Troy Lee

              Comment

              • Element

                #8
                Re: Update an unbound form

                I just wanted to chime-in on Allen's reply -- as a long-time Access/
                SQL developer currently dealing with a couple huge Access applications
                that use 90% unbound forms, I say say for sure that bound forms should
                be used whenever possible.


                On Sep 24, 10:12 am, "Allen Browne" <AllenBro...@Se eSig.Invalid>
                wrote:
                Why are you using an unbound form?

                Comment

                Working...