Solved

Access VBA / SQL - Insert, Select and Where statement error

Posted on 2011-09-28
6
1,057 Views
Last Modified: 2012-05-12
Hi Experts,

I need your help. Can someone please review this SQL VB statement for me. i cant seem to make it work from a push of a button on a form.

strSQL1c = "INSERT INTO [ar_client]([uniqueid_c],[clientcode_c],[firstname_vc],[lastname_vc],[create_dt],[createuser_c],[touch_date],[collection_c],[touch_user],[arnoteid_c])SELECT" & _
"[dbo_IDgenerator.cluniqueID],[dbo_IDgenerator.clientcode_c],[dbo_IDgenerator.firstname_vc],[dbo_IDgenerator.lastname_vc],[dbo_IDgenerator.create_dt],[dbo_IDgenerator.createuser_c],[dbo_IDgenerator.create_dt],'n' AS [collection_c],[dbo_IDgenerator.createuser_c],[dbo_IDgenerator.cluniqueID] AS arnoteid_c" & _
"From [dbo_IDgenerator] WHERE ((([dbo_IDgenerator.createstatus])='SMF-Pending'))"
0
Comment
Question by:bootyfreakk
  • 3
  • 2
6 Comments
 
LVL 75
ID: 36719930
Seems you are missing an Execute statement:

strSQL1c = "INSERT INTO [ar_client]([uniqueid_c],[clientcode_c],[firstname_vc],[lastname_vc],[create_dt],[createuser_c],[touch_date],[collection_c],[touch_user],[arnoteid_c])SELECT" & _
"[dbo_IDgenerator.cluniqueID],[dbo_IDgenerator.clientcode_c],[dbo_IDgenerator.firstname_vc],[dbo_IDgenerator.lastname_vc],[dbo_IDgenerator.create_dt],[dbo_IDgenerator.createuser_c],[dbo_IDgenerator.create_dt],'n' AS [collection_c],[dbo_IDgenerator.createuser_c],[dbo_IDgenerator.cluniqueID] AS arnoteid_c" & _
"From [dbo_IDgenerator] WHERE ((([dbo_IDgenerator.createstatus])='SMF-Pending'))"

CurrentDB.Execute strSQL1c , dbFailOnError

0
 
LVL 3

Author Comment

by:bootyfreakk
ID: 36719947
im using
 DoCmd.RunSQL strSQL1c

 to run this statement. let me try that code.
 
0
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 300 total points
ID: 36719962
You need more spaces:

strSQL1c = "INSERT INTO [ar_client] ([uniqueid_c],[clientcode_c],[firstname_vc],[lastname_vc], " & _
    "[create_dt],[createuser_c],[touch_date],[collection_c],[touch_user],[arnoteid_c]) " & _
    "SELECT [dbo_IDgenerator.cluniqueID],[dbo_IDgenerator.clientcode_c]," & _
    "[dbo_IDgenerator.firstname_vc],[dbo_IDgenerator.lastname_vc]," & _
    "[dbo_IDgenerator.create_dt],[dbo_IDgenerator.createuser_c],[dbo_IDgenerator.create_dt]," & _
    "'n' AS [collection_c],[dbo_IDgenerator.createuser_c],[dbo_IDgenerator.cluniqueID] AS arnoteid_c " & _
    "From [dbo_IDgenerator] WHERE [dbo_IDgenerator.createstatus]='SMF-Pending'" 

Open in new window

0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 75
ID: 36719973
Whereas the Execute method is better, that's not the issue then.

What Exactly is the error you are getting ?

My guess ... try this:


WHERE ((([dbo_IDgenerator.createstatus])=" & Chr(34) & "SMF-Pending" & Chr(34) ))"
0
 
LVL 3

Author Comment

by:bootyfreakk
ID: 36720016
still wont let me run it. i'm missing something or wrote something wrong.
 on a simple query if you paste in
INSERT INTO ar_client ( uniqueid_c, clientcode_c, firstname_vc, lastname_vc, create_dt, createuser_c, touch_date, collection_c, touch_user, arnoteid_c )
SELECT dbo_IDgenerator.cluniqueID, dbo_IDgenerator.clientcode_c, dbo_IDgenerator.firstname_vc, dbo_IDgenerator.lastname_vc, dbo_IDgenerator.create_dt, dbo_IDgenerator.createuser_c, dbo_IDgenerator.create_dt, "n" AS collection_c, dbo_IDgenerator.createuser_c, dbo_IDgenerator.cluniqueID AS arnoteid_c
FROM dbo_IDgenerator
WHERE (((dbo_IDgenerator.createstatus)="SMF-Pending"));

you can see what i'm trying to achive. the simple query works but i would like to use a SQL insert instead.
0
 
LVL 3

Author Comment

by:bootyfreakk
ID: 36720064
Hey matthewspatrick
It worked like a charm. Thanks your your help.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
unable to save new report from old one 9 30
Best way to create dynamic, short cut menu 7 28
vba sql wild card passing in code 3 24
SQL multicriteria from ONE textbox 32 43
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question