Solved

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

Posted on 2011-09-28
6
1,076 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

733 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