Solved

insert statement in vba

Posted on 2014-10-28
2
235 Views
Last Modified: 2014-11-06
Hi,
I was wondering if I can get some help with an insert statement I am running in vba.

I need to insert some records based on the current form

my code is something like this:
CurrentDb.Execute "insert into SER_FAXES_FILE ([ID],[STAFF-Resource NAME OT], [ADDRESS UNIQUE ID]) values (SELECT [ID],[STAFF-Resource NAME OT], [ADDRESS UNIQUE ID] from SER_FAXES_FILE_daily where SER_FAXES_FILE.ID = me.id))"

Open in new window


can I do a insert with a select statement with currentdb.execute? its erroriing out

thanks in advance
Vinnie
0
Comment
Question by:damixa
2 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 40408792
if the ID field is Number

CurrentDb.Execute "insert into SER_FAXES_FILE ([ID],[STAFF-Resource NAME OT], [ADDRESS UNIQUE ID]) SELECT [ID],[STAFF-Resource NAME OT], [ADDRESS UNIQUE ID] from SER_FAXES_FILE_daily where SER_FAXES_FILE.ID =" & me.id

if the ID field is TEXT

CurrentDb.Execute "insert into SER_FAXES_FILE ([ID],[STAFF-Resource NAME OT], [ADDRESS UNIQUE ID]) SELECT [ID],[STAFF-Resource NAME OT], [ADDRESS UNIQUE ID] from SER_FAXES_FILE_daily where SER_FAXES_FILE.ID ='" & me.id & "'"
0
 
LVL 7

Expert Comment

by:slubek
ID: 40409343
Create stored procedure on server side and exec it with something like:
CurrentDb.Execute "exec sp_yourprocedurename " & [ID] & ", " & [STAFF-Resource NAME OT] (etc.)

Open in new window

First of all - you can embed into SP any logic you want, second, you can exec that procedure from more application functions than one.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now