Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8535461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:26:12+00:00 2026-06-11T10:26:12+00:00

I have just started to do some coding with Access and trying to create

  • 0

I have just started to do some coding with Access and trying to create a function that adds a row to a table but this would not work.

I have created a simple table (Table1) with two columns “FirstName” and “LastName” and a button that fires off the following code:

Private Sub Command0_Click()
    AppendRow "Table1", "John", "Doe"
End Sub

Where AppendRow is:

Function AppendRow(toTableName As String, firstName As String, lastName As String) As Boolean
   ' Returns True on success, false otherwise
   ' USAGE: AppendRow "toTableName", "firstName", "lastName"

   On Error GoTo errhandler
   Dim strSql As String

   'Create the SQL string
   strSql = "INSERT INTO " & toTableName & " (FirstName, LastName) " & _
        "VALUES ('" & firstName & "', '" & lastName & "');"


   'Print the SQL so we can paste into the query build if there are errors
   Debug.Print strSql
   MsgBox strSql

   'Run the SQL Query
   CurrentDb.Execute strSql

   'If no errors return true
   AppendRow = True

ExitHere:
   Exit Function

errhandler:
   'There is an error return false
   AppendRow = False
   With Err
      MsgBox "Error " & .Number & vbCrLf & .Description, vbOKOnly Or vbCritical, "AppendTable"
   End With
   Resume ExitHere
End Function

The SQL string looks like this

INSERT INTO Table1 (FirstName, LastName) VALUES ('John', 'Doe')

EDIT: Added missing quotes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:26:13+00:00Added an answer on June 11, 2026 at 10:26 am

    You reported that you are now quoting the text values you attempt to insert, but that you do not get the row inserted and apparently no error message. I don’t understand why that is so, and offer this simple procedure simply to see whether you can get something to work.

    Public Sub AppendRow(ByVal toTableName As String, _
            ByVal pFirstName As String, _
            ByVal pLastName As String)
        Dim db As DAO.Database
        Dim rs As DAO.Recordset
        '* ensure SetWarnings is not off *'
        DoCmd.SetWarnings True
        Set db = CurrentDb
        Set rs = db.OpenRecordset(toTableName, dbOpenTable, dbAppendOnly)
        With rs
            .AddNew
            !firstName = pFirstName
            !lastName = pLastName
            .Update
            .Close
        End With
        Set rs = Nothing
        Set db = Nothing
    End Sub
    

    I didn’t include error handling because this is intended only for testing. I made it a subroutine instead of a function because I noticed you weren’t using the function’s return value in your code which called the function.

    If this doesn’t work for you, please tell us the error message you receive and which line in that procedure triggers the error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just started using NHibernate, and I have some issues that I'm unsure how
I have just started learning python version 3 and trying to create a file
I have just started out with testing some php mvc framework In it, it
I have just started to play with Play framework (2.0) and I'm having some
I just started using/learning Python and have some questions. I have a text file
I have just started using OutputCache on some of my controller actions and I
A beginner question I am sure, but I have just started working with a
I just started coding an application, my idea is to create something like StreamMyGame
we have just started using a git account of our Django website project so
I have just started using RSpec and I copied the very simple test on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.