Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Insert Into in Code

Status
Not open for further replies.

Drenda

Programmer
Sep 1, 2007
85
GB
Can anyone help
I am trying to run an append query using insert into in visual basic and thought I could simply copy from the SQL into the code window for my form

I have pasted the following but no matter what I try to change in terms on syntax I cannot seem to get it right

Docmd.Run SQL INSERT INTO [LWDC (LWDC) UNEXPECTED] ( [3 Digit Category], Budget, [Jan Actuals], [Feb Actuals], [Mar Actuals], [Apr Actuals], [May Actuals], [Ju Actuals], [Jul Actuals], [Aug Actuals], [Sep Actuals], [Oct Actuals], [Nov Actuals], [Dec Actuals], [Commitment to Spend], [Total Spend] )
SELECT [Cost Authorisation Spend Report UNEXPECTED Append Table].[3 Digit Category], [Cost Authorisation Spend Report UNEXPECTED Append Table].Budget, [Cost Authorisation Spend Report UNEXPECTED Append Table].[Jan Actuals], [Cost Authorisation Spend Report UNEXPECTED Append Table].[Feb Actuals], [Cost Authorisation Spend Report UNEXPECTED Append Table].[Mar Actuals], [Cost Authorisation Spend Report UNEXPECTED Append Table].[Apr Actuals], [Cost Authorisation Spend Report UNEXPECTED Append Table].[May Actuals], [Cost Authorisation Spend Report UNEXPECTED Append Table].[Ju Actuals], [Cost Authorisation Spend Report UNEXPECTED Append Table].[Jul Actuals], [Cost Authorisation Spend Report UNEXPECTED Append Table].[Aug Actuals], [Cost Authorisation Spend Report UNEXPECTED Append Table].[Sep Actuals], [Cost Authorisation Spend Report UNEXPECTED Append Table].[Oct Actuals], [Cost Authorisation Spend Report UNEXPECTED Append Table].[Nov Actuals], [Cost Authorisation Spend Report UNEXPECTED Append Table].[Dec Actuals], [Cost Authorisation Spend Report UNEXPECTED Append Table].[Commitment to Spend], [Cost Authorisation Spend Report UNEXPECTED Append Table].[Total Spend]
FROM [Cost Authorisation Spend Report UNEXPECTED Append Table];
 
Place the cursor inside the RunSQL word in your code and then press the F1 key.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Drenda

Prefer to alias long table/querie' s names (like the 55 char length of yours) and format your SQL statements since they can be very much better read, even by you.

As a general rule, avoid the use of DoCmd.RunSql since it wakes-up the warning messages and prefer CurrentDB.Execute method wich does the some thing (execute action queries) without the annoying warnings.
The whole SQL statement should be enclosed in double quotes in both cases.

Code:
Dim strSQL As String

strSQL = "INSERT INTO [LWDC (LWDC) UNEXPECTED] (" & _
                "[3 Digit Category], " & _
                "Budget, " & _
                "[Jan Actuals], " & _
                "[Feb Actuals], " & _
                "[Mar Actuals], " & _
                "[Apr Actuals], " & _
                "[May Actuals], " & _
                "[Ju  Actuals], " & _
                "[Jul Actuals], " & _
                "[Aug Actuals], " & _
                "[Sep Actuals], " & _
                "[Oct Actuals], " & _
                "[Nov Actuals], " & _
                "[Dec Actuals], " & _
                "[Commitment to Spend], " & _
                "[Total Spend] ) " & _
         "SELECT T1.[3 Digit Category], " & _
                "T1.Budget, " & _
                "T1.[Jan Actuals], " & _
                "T1.[Feb Actuals], " & _
                "T1.[Mar Actuals], " & _
                "T1.[Apr Actuals], " & _
                "T1.[May Actuals], " & _
                "T1.[Ju  Actuals], " & _
                "T1.[Jul Actuals], " & _
                "T1.[Aug Actuals], " & _
                "T1.[Sep Actuals], " & _
                "T1.[Oct Actuals], " & _
                "T1.[Nov Actuals], " & _
                "T1.[Dec Actuals], " & _
                "T1.[Commitment to Spend], " & _
                "T1.[Total Spend] " & _
"FROM [Cost Authorisation Spend Report UNEXPECTED Append Table] As T1;"

CurrentDB.Execute strSQL
 
Please read faq181-2886 with particular reference to point 15.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top