Populata NewRecord from Text boxes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RICHARD BROMBERG

    Populata NewRecord from Text boxes

    I am using Access 2000 and I would like to make a data entry form
    (frmDataEntry)

    I want to append a newrecord to a table (tblPeople) and populate the new
    record from two Textboxes (txtName and txtAge) The table has two fields,
    Name and Age.

    I used a command button (the command button wizard, record operations,Add
    New Record) and it generates the code snippet below.

    I think I have to add some code in the area I marked with question marks in
    the snippet, something like:
    XXXXXXX = Me.txtName and YYYYYYYY = Me.txtAge.

    How do I refer to the Name and Age fields in the new record?

    Help would be greatly appreciated.

    *************** ***** snippet ***********
    Private Sub commandAddRecor d_Click()

    On Error GoTo Err_commandAddR ecord_Click
    DoCmd.GoToRecor d , , acNewRec
    '
    ' ?? move data from textboxes to table??
    '
    Exit_commandAdd Record_Click:
    Exit Sub

    Err_commandAddR ecord_Click:
    MsgBox Err.Description
    Resume Exit_commandAdd Record_Click

    End Sub

    *************** ***** snippet ***********


  • Salad

    #2
    Re: Populata NewRecord from Text boxes

    RICHARD BROMBERG wrote:
    I am using Access 2000 and I would like to make a data entry form
    (frmDataEntry)
    >
    I want to append a newrecord to a table (tblPeople) and populate the new
    record from two Textboxes (txtName and txtAge) The table has two fields,
    Name and Age.
    >
    I used a command button (the command button wizard, record operations,Add
    New Record) and it generates the code snippet below.
    >
    I think I have to add some code in the area I marked with question marks in
    the snippet, something like:
    XXXXXXX = Me.txtName and YYYYYYYY = Me.txtAge.
    >
    How do I refer to the Name and Age fields in the new record?
    >
    Help would be greatly appreciated.
    >
    *************** ***** snippet ***********
    Private Sub commandAddRecor d_Click()
    >
    On Error GoTo Err_commandAddR ecord_Click
    DoCmd.GoToRecor d , , acNewRec
    '
    ' ?? move data from textboxes to table??
    '
    Exit_commandAdd Record_Click:
    Exit Sub
    >
    Err_commandAddR ecord_Click:
    MsgBox Err.Description
    Resume Exit_commandAdd Record_Click
    >
    End Sub
    >
    *************** ***** snippet ***********
    >
    >
    You could put, in the default value of Age, something like
    =Forms!frmDataE ntry!txtAge
    then
    =Forms!fmrDataE ntry.txtName
    for the name field.

    Comment

    • Salad

      #3
      Re: Populata NewRecord from Text boxes

      Salad wrote:
      RICHARD BROMBERG wrote:
      >
      >I am using Access 2000 and I would like to make a data entry form
      >(frmDataEntr y)
      >>
      >I want to append a newrecord to a table (tblPeople) and populate the
      >new record from two Textboxes (txtName and txtAge) The table has two
      >fields, Name and Age.
      >>
      >I used a command button (the command button wizard, record
      >operations,A dd New Record) and it generates the code snippet below.
      >>
      >I think I have to add some code in the area I marked with question
      >marks in the snippet, something like:
      >XXXXXXX = Me.txtName and YYYYYYYY = Me.txtAge.
      >>
      >How do I refer to the Name and Age fields in the new record?
      >>
      >Help would be greatly appreciated.
      >>
      >************** ****** snippet ***********
      >Private Sub commandAddRecor d_Click()
      >>
      >On Error GoTo Err_commandAddR ecord_Click
      > DoCmd.GoToRecor d , , acNewRec
      >'
      >' ?? move data from textboxes to table??
      >'
      >Exit_commandAd dRecord_Click:
      > Exit Sub
      >>
      >Err_commandAdd Record_Click:
      > MsgBox Err.Description
      > Resume Exit_commandAdd Record_Click
      >>
      >End Sub
      >>
      >************** ****** snippet ***********
      >>
      You could put, in the default value of Age, something like
      =Forms!frmDataE ntry!txtAge
      then
      =Forms!fmrDataE ntry.txtName
      for the name field.
      That's frm, not frm.

      Comment

      • tina

        #4
        Re: Populata NewRecord from Text boxes

        you have several issues here. first, you should rename the table field
        called "Name", which is an Access Reserved Word and should NOT be used as
        the name of anything *you* create in the database, including tables, fields,
        queries, forms, reports, form/report controls, macros, modules and
        procedures. for more information, see
        http://home.att.net/~california.db/tips.html#aTip5.

        next, a person's age is a calculated value based on his/her date of birth
        subtracted from the current date. storing a calculated value in a table is
        considered poor design. the only exception i can think of would be if the
        record is historical data and you have a business need to know what the
        person's age was *at that point in time*, rather than their current age.
        even then, i'd probably date-stamp the record, and calculate the age using
        that date, rather than storing a hard age value.

        next, if you only have one field for the name, and if we're talking about
        people here (not businesses, organizations, etc), then you are breaking
        normalization rules, which require atomic data storage - separate fields for
        first name, last name, middle name or initial if it's needed. suggest you
        read up on relational design principles; for more information, see
        http://home.att.net/~california.db/tips.html#aTip1.

        now, having said all of the above, what is the RecordSource of frmDataEntry?
        if the RecordSource is blank, then enter tblPeople in that property. now the
        form is bound to tblPeople. set the ControlSource property of txtName to
        Name, and the ControlSource of txtAge to Age. now you can just enter the
        name and age in the form, and the values will be written to a new record in
        the underlying table.

        if frmDataEntry is already bound to another table (not tblPeople), you can
        run an Append query to add the name and age to tblPeople (refer back to the
        comments above re table design), as

        CurrentDb.Execu te "INSERT INTO tblPeople ( Name, Age ) " _
        & "SELECT '" & Me!txtName & "', " & Me!txtAge

        the above SQL statement's syntax assumes that the Name field in tblPeople
        has a Data Type of Text, and the Age field has a data type of Number.

        but i strongly urge you to read up on relational design principles and
        reconsider your table design before moving forward.

        hth


        "RICHARD BROMBERG" <dickbrom@world net.att.netwrot e in message
        news:IeXTk.1356 06$Mh5.97332@bg tnsc04-news.ops.worldn et.att.net...
        I am using Access 2000 and I would like to make a data entry form
        (frmDataEntry)
        >
        I want to append a newrecord to a table (tblPeople) and populate the new
        record from two Textboxes (txtName and txtAge) The table has two fields,
        Name and Age.
        >
        I used a command button (the command button wizard, record operations,Add
        New Record) and it generates the code snippet below.
        >
        I think I have to add some code in the area I marked with question marks
        in
        the snippet, something like:
        XXXXXXX = Me.txtName and YYYYYYYY = Me.txtAge.
        >
        How do I refer to the Name and Age fields in the new record?
        >
        Help would be greatly appreciated.
        >
        *************** ***** snippet ***********
        Private Sub commandAddRecor d_Click()
        >
        On Error GoTo Err_commandAddR ecord_Click
        DoCmd.GoToRecor d , , acNewRec
        '
        ' ?? move data from textboxes to table??
        '
        Exit_commandAdd Record_Click:
        Exit Sub
        >
        Err_commandAddR ecord_Click:
        MsgBox Err.Description
        Resume Exit_commandAdd Record_Click
        >
        End Sub
        >
        *************** ***** snippet ***********
        >
        >

        Comment

        • RICHARD BROMBERG

          #5
          Re: Populata NewRecord from Text boxes

          Thanks

          In the statement you suggest, copied below the parentheses are incorrect

          CurrentDb.Execu te "INSERT INTO tblPeople ( Name, Age ) " _
          & "SELECT '" & Me!txtName & "', " & Me!txtAge

          "tina" <nospam@address .comwrote in message
          news:5FYTk.1357 70$Mh5.71774@bg tnsc04-news.ops.worldn et.att.net...
          you have several issues here. first, you should rename the table field
          called "Name", which is an Access Reserved Word and should NOT be used as
          the name of anything *you* create in the database, including tables,
          fields,
          queries, forms, reports, form/report controls, macros, modules and
          procedures. for more information, see
          http://home.att.net/~california.db/tips.html#aTip5.
          >
          next, a person's age is a calculated value based on his/her date of birth
          subtracted from the current date. storing a calculated value in a table is
          considered poor design. the only exception i can think of would be if the
          record is historical data and you have a business need to know what the
          person's age was *at that point in time*, rather than their current age.
          even then, i'd probably date-stamp the record, and calculate the age using
          that date, rather than storing a hard age value.
          >
          next, if you only have one field for the name, and if we're talking about
          people here (not businesses, organizations, etc), then you are breaking
          normalization rules, which require atomic data storage - separate fields
          for
          first name, last name, middle name or initial if it's needed. suggest you
          read up on relational design principles; for more information, see
          http://home.att.net/~california.db/tips.html#aTip1.
          >
          now, having said all of the above, what is the RecordSource of
          frmDataEntry?
          if the RecordSource is blank, then enter tblPeople in that property. now
          the
          form is bound to tblPeople. set the ControlSource property of txtName to
          Name, and the ControlSource of txtAge to Age. now you can just enter the
          name and age in the form, and the values will be written to a new record
          in
          the underlying table.
          >
          if frmDataEntry is already bound to another table (not tblPeople), you can
          run an Append query to add the name and age to tblPeople (refer back to
          the
          comments above re table design), as
          >
          CurrentDb.Execu te "INSERT INTO tblPeople ( Name, Age ) " _
          & "SELECT '" & Me!txtName & "', " & Me!txtAge
          >
          the above SQL statement's syntax assumes that the Name field in tblPeople
          has a Data Type of Text, and the Age field has a data type of Number.
          >
          but i strongly urge you to read up on relational design principles and
          reconsider your table design before moving forward.
          >
          hth
          >
          >
          "RICHARD BROMBERG" <dickbrom@world net.att.netwrot e in message
          news:IeXTk.1356 06$Mh5.97332@bg tnsc04-news.ops.worldn et.att.net...
          >I am using Access 2000 and I would like to make a data entry form
          >(frmDataEntr y)
          >>
          >I want to append a newrecord to a table (tblPeople) and populate the new
          >record from two Textboxes (txtName and txtAge) The table has two
          >fields,
          >Name and Age.
          >>
          >I used a command button (the command button wizard, record operations,Add
          >New Record) and it generates the code snippet below.
          >>
          >I think I have to add some code in the area I marked with question marks
          in
          >the snippet, something like:
          >XXXXXXX = Me.txtName and YYYYYYYY = Me.txtAge.
          >>
          >How do I refer to the Name and Age fields in the new record?
          >>
          >Help would be greatly appreciated.
          >>
          >************** ****** snippet ***********
          >Private Sub commandAddRecor d_Click()
          >>
          >On Error GoTo Err_commandAddR ecord_Click
          > DoCmd.GoToRecor d , , acNewRec
          >'
          >' ?? move data from textboxes to table??
          >'
          >Exit_commandAd dRecord_Click:
          > Exit Sub
          >>
          >Err_commandAdd Record_Click:
          > MsgBox Err.Description
          > Resume Exit_commandAdd Record_Click
          >>
          >End Sub
          >>
          >************** ****** snippet ***********
          >>
          >>
          >
          >

          Comment

          • tina

            #6
            Re: Populata NewRecord from Text boxes

            post your correction.


            "RICHARD BROMBERG" <dickbrom@world net.att.netwrot e in message
            news:ijeUk.3166 7$_Y1.4083@bgtn sc05-news.ops.worldn et.att.net...
            Thanks
            >
            In the statement you suggest, copied below the parentheses are incorrect
            >
            CurrentDb.Execu te "INSERT INTO tblPeople ( Name, Age ) " _
            & "SELECT '" & Me!txtName & "', " & Me!txtAge
            >
            "tina" <nospam@address .comwrote in message
            news:5FYTk.1357 70$Mh5.71774@bg tnsc04-news.ops.worldn et.att.net...
            you have several issues here. first, you should rename the table field
            called "Name", which is an Access Reserved Word and should NOT be used
            as
            the name of anything *you* create in the database, including tables,
            fields,
            queries, forms, reports, form/report controls, macros, modules and
            procedures. for more information, see
            http://home.att.net/~california.db/tips.html#aTip5.

            next, a person's age is a calculated value based on his/her date of
            birth
            subtracted from the current date. storing a calculated value in a table
            is
            considered poor design. the only exception i can think of would be if
            the
            record is historical data and you have a business need to know what the
            person's age was *at that point in time*, rather than their current age.
            even then, i'd probably date-stamp the record, and calculate the age
            using
            that date, rather than storing a hard age value.

            next, if you only have one field for the name, and if we're talking
            about
            people here (not businesses, organizations, etc), then you are breaking
            normalization rules, which require atomic data storage - separate fields
            for
            first name, last name, middle name or initial if it's needed. suggest
            you
            read up on relational design principles; for more information, see
            http://home.att.net/~california.db/tips.html#aTip1.

            now, having said all of the above, what is the RecordSource of
            frmDataEntry?
            if the RecordSource is blank, then enter tblPeople in that property. now
            the
            form is bound to tblPeople. set the ControlSource property of txtName to
            Name, and the ControlSource of txtAge to Age. now you can just enter the
            name and age in the form, and the values will be written to a new record
            in
            the underlying table.

            if frmDataEntry is already bound to another table (not tblPeople), you
            can
            run an Append query to add the name and age to tblPeople (refer back to
            the
            comments above re table design), as

            CurrentDb.Execu te "INSERT INTO tblPeople ( Name, Age ) " _
            & "SELECT '" & Me!txtName & "', " & Me!txtAge

            the above SQL statement's syntax assumes that the Name field in
            tblPeople
            has a Data Type of Text, and the Age field has a data type of Number.

            but i strongly urge you to read up on relational design principles and
            reconsider your table design before moving forward.

            hth


            "RICHARD BROMBERG" <dickbrom@world net.att.netwrot e in message
            news:IeXTk.1356 06$Mh5.97332@bg tnsc04-news.ops.worldn et.att.net...
            I am using Access 2000 and I would like to make a data entry form
            (frmDataEntry)
            >
            I want to append a newrecord to a table (tblPeople) and populate the
            new
            record from two Textboxes (txtName and txtAge) The table has two
            fields,
            Name and Age.
            >
            I used a command button (the command button wizard, record
            operations,Add
            New Record) and it generates the code snippet below.
            >
            I think I have to add some code in the area I marked with question
            marks
            in
            the snippet, something like:
            XXXXXXX = Me.txtName and YYYYYYYY = Me.txtAge.
            >
            How do I refer to the Name and Age fields in the new record?
            >
            Help would be greatly appreciated.
            >
            *************** ***** snippet ***********
            Private Sub commandAddRecor d_Click()
            >
            On Error GoTo Err_commandAddR ecord_Click
            DoCmd.GoToRecor d , , acNewRec
            '
            ' ?? move data from textboxes to table??
            '
            Exit_commandAdd Record_Click:
            Exit Sub
            >
            Err_commandAddR ecord_Click:
            MsgBox Err.Description
            Resume Exit_commandAdd Record_Click
            >
            End Sub
            >
            *************** ***** snippet ***********
            >
            >
            >
            >

            Comment

            • Keith Wilby

              #7
              Re: Populata NewRecord from Text boxes

              "tina" <nospam@address .comwrote in message
              news:RyfUk.3174 3$_Y1.29827@bgt nsc05-news.ops.worldn et.att.net...
              post your correction.
              >
              Some ppl have no clue how to ask for help from complete strangers for free.

              Comment

              • tina

                #8
                Re: Populata NewRecord from Text boxes

                well, i really wanted to see the correction. i copied/pasted the SQL from a
                test Append query, as i am wont to do in my day-to-day work - SQL not being
                my strongest area. since the test query ran and i didn't change the syntax,
                i'm at a loss. do you see the error, Keith? tia, tina


                "Keith Wilby" <here@there.com wrote in message
                news:49218f09$1 _1@glkas0286.gr eenlnk.net...
                "tina" <nospam@address .comwrote in message
                news:RyfUk.3174 3$_Y1.29827@bgt nsc05-news.ops.worldn et.att.net...
                post your correction.
                >
                Some ppl have no clue how to ask for help from complete strangers for
                free.
                >

                Comment

                • Keith Wilby

                  #9
                  Re: Populata NewRecord from Text boxes

                  "tina" <nospam@address .comwrote in message
                  news:O_qUk.3249 9$_Y1.3595@bgtn sc05-news.ops.worldn et.att.net...
                  well, i really wanted to see the correction. i copied/pasted the SQL from
                  a
                  test Append query, as i am wont to do in my day-to-day work - SQL not
                  being
                  my strongest area. since the test query ran and i didn't change the
                  syntax,
                  i'm at a loss. do you see the error, Keith? tia, tina
                  >
                  >
                  I saw no error with the parentheses but having looked again I think it
                  should read

                  "INSERT INTO tblPeople ( Name, Age ) Values ('" & Me.txtName & "', " &
                  Me.txtAge & ")"

                  Keith.


                  Comment

                  • tina

                    #10
                    Re: Populata NewRecord from Text boxes

                    hmm, well, the SELECT does work - that's what i always use. do you know if
                    there's an upside/downside to SELECT vs Values? tia, tina


                    "Keith Wilby" <here@there.com wrote in message
                    news:49227f95$1 _1@glkas0286.gr eenlnk.net...
                    "tina" <nospam@address .comwrote in message
                    news:O_qUk.3249 9$_Y1.3595@bgtn sc05-news.ops.worldn et.att.net...
                    well, i really wanted to see the correction. i copied/pasted the SQL
                    from
                    a
                    test Append query, as i am wont to do in my day-to-day work - SQL not
                    being
                    my strongest area. since the test query ran and i didn't change the
                    syntax,
                    i'm at a loss. do you see the error, Keith? tia, tina
                    >
                    I saw no error with the parentheses but having looked again I think it
                    should read
                    >
                    "INSERT INTO tblPeople ( Name, Age ) Values ('" & Me.txtName & "', " &
                    Me.txtAge & ")"
                    >
                    Keith.

                    >

                    Comment

                    Working...