Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Sunrise, Florida
    Posts
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Append/Add Single Record (2003)

    I created a form with 5 unbound Text Boxes; intSubjectID, strSubjectName, strSocSecNo, strLicNo, and datDOB. I want to be able to collect the info typed into the boxes and add it to the Table tblSubjects. I've seen here some alternatives but I don't want to give the users access to the raw data. Not just yet. As always, any assistance is appreciated. Thanks!

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Append/Add Single Record (2003)

    You can put a command button cmdSave with caption "Save" on the form. Use code like this in the On Click event of the button:
    <code>
    Private Sub cmdSave_Click()
    Dim strSQL As String
    strSQL = "INSERT INTO tblSubjects (intSubjectID, strSubjectName, strSocSecNo, strLicNo, datDOB) " & _
    VALUES(" & Me.intSubjectID & ",'" & Me.strSubjectName & "', '" & Me.strSocSecNo & "', '" & _
    Me.strLicNo & "', #" & Format(Me.datDOB, "mm/dd/yyyy") & "#)"
    CurrentDb.Execute strSQL, dbFailOnError
    End Sub
    </code>
    Substitute the correct field names if necessary. Note that text values are enclosed in single quotes <code>'</code> and date values in <code>#</code> characters.

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Sunrise, Florida
    Posts
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Append/Add Single Record (2003)

    HansV ... once again, Thanks! I get a syntax error in the SQL statement. Thanks in advance for any help!

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Append/Add Single Record (2003)

    Please excuse me, I forgot the opening double quote before VALUES:
    <code>
    Private Sub cmdSave_Click()
    Dim strSQL As String
    strSQL = "INSERT INTO tblSubjects (intSubjectID, strSubjectName, strSocSecNo, strLicNo, datDOB) " & _
    "VALUES (" & Me.intSubjectID & ",'" & Me.strSubjectName & "', '" & Me.strSocSecNo & "', '" & _
    Me.strLicNo & "', #" & Format(Me.datDOB, "mm/dd/yyyy") & "#)"
    CurrentDb.Execute strSQL, dbFailOnError
    End Sub</code>

  5. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Sunrise, Florida
    Posts
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Append/Add Single Record (2003)

    Hey ... HansV ... no need to apologize ... works like a charm! Thanks a whole lot!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •