Hi,
I try to run several insert into sql statements in direct MS access at same time. For ex.
INSERT INTO Mytable(F1, F2) VALUES('V11', 'V12')
INSERT INTO Mytable(F1, F2) VALUES('V21', 'V22')
INSERT INTO Mytable(F1, F2) VALUES('V31', 'V32')
INSERT INTO Mytable(F1, F2) VALUES('V41', 'V42')
How can I do it? Any hints?
It seems that MS Access editor does not support several INSERT INTO statements running at the same time. Right?
Thanks in advance.
- Loi -
12 10681 PEB 1,418
Recognized Expert Top Contributor
Yeah
It's thrut!
However you can pass a SQLs to a function that runs them
like:
Docmd.RunSql "SQL"
one after other
NeoPa 32,557
Recognized Expert Moderator MVP
If you look up under help for the Execute method from a connection / querydef, you should find reference to dbRunAsync Executes the query asynchronously (ODBCDirect Connection and QueryDef objects only).
You will have to manage determinating when they're all complete in your code.
The help explains it fairly fully.
PEB 1,418
Recognized Expert Top Contributor
If you look up under help for the Execute method from a connection / querydef, you should find reference to
You will have to manage determinating when they're all complete in your code.
The help explains it fairly fully.
Yeap maybe if the backend database is different from Access using db.Execute can execute multiple actions...
But different database... Not the Jet!
NeoPa 32,557
Recognized Expert Moderator MVP
Sorry PEB.
This also supports QueryDef objects in Jet as well.
That means it must be a saved query (not just a SQL string - I think).
PEB 1,418
Recognized Expert Top Contributor
In fact in my database i'm using always
mydb.Execute (SQL)
with SQL string... And never tried to use it with QueryDef /Saved query/ And don't know if it works with saved query
I should test it!
But first create an Action query and save it... coz all my action queries aren't saved...
Maybe this is true for Make tables queries... that i don't use??? I've remembrerd thet there was a pb with action query that produces a table as result!
NeoPa 32,557
Recognized Expert Moderator MVP
Don't forget that the Execute procedure works with Connections or Databases in one format, but also with QueryDefs in another. Execute Method
Runs an action query or executes an SQL statement on a specified Connection or Database object.
Syntax
object.Execute source, options
querydef.Execute options
The Execute method syntax has these parts.
Part Description object A Connection or Database object variable on which the query will run. querydef An object variable that represents the QueryDef object whose SQL property setting specifies the SQL statement to execute. source A String that is an SQL statement or the Name property value of a QueryDef object. options Optional. A constant or combination of constants that determines the data integrity characteristics of the query, as specified in Settings.
PEB 1,418
Recognized Expert Top Contributor
Sure , and it seems that it was one of the methods to run a parameterd action query...
Before using the Querydef.execute,
declaring the parameters like
querydef("[Myparameter1]")="test1"
querydef("[Myparameter1]")="test2"
and so on..
And how difficulties i've had till i found this method...
nico5038 3,080
Recognized Expert Specialist
When saved queries are needed (like for some docmd.transfer... commands) I usually use the Tabledef object like:
dim td as DAO.querydef
set td = currentdb.querydefs ("qryDummy") ' this needs to be defined !
td.SQL = "INSERT bla bla bla..."
Now all processing with qryDummy can be executed with the filled SQL.
In this case of a number of INSERT queries you could import the statements into a table and add a recordset processing loop to execute the assign statement like:
td.SQL = rs!querySQL
docmd.runquery (td.name)
Idea ?
Nic;o)
NeoPa 32,557
Recognized Expert Moderator MVP
Nice idea Nico.
I use a similar concept sometimes (only when there's some reason strSQL doesn't work properly).
I find that the Record Locks, Recordset Type and ODBC Timeout properties can be critical in the execution of some queries so I have a dummy QueryDef set with my default values that I reuse (I usually make a copy before amending though).
From the context, I think the original problem that ltanvo had was that he/she was trying to do multiple INSERTs in the SQL view of the Query editor. Which you can't do, obviously.
ltanvo, if this is the case, you could create a macro to issue the series of INSERTs as a bunch of RunSQL commands.
NeoPa 32,557
Recognized Expert Moderator MVP
LOL - that's ironic.
I think your interpretation must be the right one Killer. It didn't occur to me to look at it that way.
I thought it was a funny sort of (advanced) question for someone to ask in that way.
Well if anyone's interested in the other (probably unrequired) info - it's all there!
BTW That can be done on other servers (MS SQL for instance) by separating each SQL instruction with a ';'. I'm pretty sure that's not supported in Access though (except via Pass-Through Queries to other systems).
MMcCarthy 14,534
Recognized Expert Moderator MVP
Create a loop.
Do until some trigger
Obtain two values and put into local variables.
DoCmd.RunSQL "INSERT INTO TableName (Field1, Field2) VALUES (" & variable1 & "," variable2 & ");"
Loop
Note: string variables will need to be enclosed with single quotes as well.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Paul |
last post by:
I have run into a strange problem with a site I am working on. My SELECT
queries work fine, but I just tried to add an UPDATE statement and it fails.
A test showed that INSERT fails also. I created...
|
by: Philip Boonzaaier |
last post by:
I want to be able to generate SQL statements that will go through a list of
data, effectively row by row, enquire on the database if this exists in the
selected table- If it exists, then the colums...
|
by: Paul Shaw |
last post by:
Can anyone explain why an insert might cause multiple logical
bufferpool data reads?
Here's a situation that has me scratching my head.
Table A's data resides in tablespace B
Table A's...
|
by: robert |
last post by:
been ruminating on the question (mostly in a 390/v7 context) of
whether, and if so when, a row update becomes an insert/delete.
i assume that there is a threshold on the number of columns of
the...
|
by: swapna_munukoti |
last post by:
Hi all,
I was trying to insert few records(approximately 1000) into access
DB from two different machines simultaneously using insert query. I am
using Begin and commit transaction. After every...
| |
by: Bob Alston |
last post by:
I have a routine to copy data to new versions of my app via insert into
sql statements. Unfortunately, due to evolution of my app, sometimes
the new version has more restrictive editing than an...
|
by: Michel Esber |
last post by:
Hello,
DB2 V8 LUW FP 11.
My applications eventually takes a very long time to process simple
insert statements.
Here´s the output of a event monitor:
Text : INSERT INTO MyTable...
|
by: unwantedspam |
last post by:
Hi All,
Thank you in advance. I am trying to insert into two tables but I am
getting the following error: "You cannot add or change a record because
a related record is required in table..." I am...
|
by: Ben |
last post by:
I don't know whether anyone can help, but I have an odd problem. I have
a PSP (Spyce) script that makes many calls to populate a database. They
all work without any problem except for one...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |