Solved

insert statement in vba

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

747 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

12 Experts available now in Live!

Get 1:1 Help Now