Solved

insert statement in vba

Posted on 2014-10-28
2
237 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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) 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

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

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…
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 views 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 Access…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

786 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