Using MS Access/Append queries

Advertisement


Question
Thanks Geoff for your reply and follow-up. Unfortunately I have lost your reply to my folloup but did have a print of it therefore I have made the changed as follows but having an error message with the "VALUES"

DoCmd.SetWarnings False
sSQL = "INSERT INTO [APPLICATIONS]( SSN, FNAME, LNAME, RECEIVED, CODE, CLOSED, INITIALS ) & _
" VALUES('"& Me.SSN & "'," & Me.FNAME & "," & Me,LNAME & ", " & Me,RECEIVED & ", " & Me,CODE & ", " & Me,CLOSED & ", " & Me,INITIALS );"
DoCmd.RunSQL sSQL
DoCmd.SetWarnings True

The "VALUE line gets highlted in red and a compile error: "End of Statement" show up. Any idea? Thanks and sorry for the delay in answering (was sick with flue a few days!).
-------------------------
Followup To
Question -
Hello,
I would like to create an update query to append a current record (a record that I am currently entering in a form) from that form which has it's record source to Table A to another table, named Table B. Both tables have the same fields and the primary key is for both the field ID which is Autonumber.

Form A is the form which will have the current record to copy into Table B.
Is there a way I can copy the current record, meaning the one I have just typed into Table B?
I have tried to create the query but having some problems. I believe it is do to with the fact the my form A has not been closed therefore the data has not been stored yet into it's table.
But if I close it how will the data be copied?
I have tried to add a criteria to a field (ssn) of my form A, like [forms]![formname]![ssn] hoping that it would clone the data but still cannot make it working.
Could it be something to do with the AutoNumber PK?
Do you have some solution? Tanks.
Answer -
Hi JohnPaul

1. Try canging the design of Table B so that its PK is Number LONG instead of autonumber.

2. The form's Current event ocurrs each time you change records, so this is an ideal time to copy the record through. The code could pick up the values directly from the form..

Sub Form_Current()

Dim sSQL as String

  DoCmd.SetWarnings False
  sSQL = "INSERT INTO table_B( Aaa, Bbb, Ccc . . ) & _
         " VALUES ( '" & Me.Aaaa & "', " & Me.Bbbb & ", " & Me,Ccc ..... & " );"
  DoCmd.RunSQL sSQL
  DoCmd.SetWarnings True

End Sub

In the above Aaa is a text item and Bbb/Ccc are numeric..

I hope this helps

Kind regards

Geoff


Answer
Hi John Paul

Try inserting a quote (") at the end of the INSERT line (my typo), plus you may need single quotes (') in the VALUES line to delineate text - I have inserted them around LNAME & FNAME. Numerics don't need the single quotes. Also change out commas for periods.

DoCmd.SetWarnings False
sSQL = "INSERT INTO [APPLICATIONS]( SSN, FNAME, LNAME, RECEIVED, CODE, CLOSED, INITIALS )" & _
" VALUES('"& Me.SSN & "', '" & Me.FNAME & "', '" & Me.LNAME & "', " & Me.RECEIVED & ", " & Me.CODE & ", " & Me.CLOSED & ", " & Me.INITIALS );"
DoCmd.RunSQL sSQL

Have another go and feeback if you need more help

Kind regards

Geoff

DoCmd.SetWarnings True

Using MS Access

All Answers


Answers by Expert:


Ask Experts

Volunteer


Geoff

Expertise

I specialise in database analysis and design, SQL and database queries using QBE and VBA. In my work, I use MS Access together with MS SQL Server as ETL (Extraction - Transformation - Loading) tools for migrating data between business ERP systems and data stores. My forte is building bespoke functions and applications.


See my website for example apps and downloads

Experience

I am a chartered engineer with 30 years of engineering and business experience, member of the BCS and have been working specifically in database applications, including SQL Server (v7/8/2000) for the last 9 or so years. I previously taught a course in Database Analysis and Design, but am now a freelance consultant and systems analyst.

Commercial database design and development work undertaken.

©2012 About.com, a part of The New York Times Company. All rights reserved.