473,626 Members | 3,031 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I was *forced* to use RunSQL

Access 2000/Windows 2000 Pro with all current updates on the client; SQL Server
7.0/Windows 2000 Server with all current updates on the server.

Bottom line: In a certain context dbs.Execute strSQL, dbfailonerror would cause
Access to GPF, whilst DoCmd.RunSQL strSQL, True would perform as expected.

The context is nothing special, but MUST have something to do with it, even
though I've done this 1000X before. In the AfterUpdate Event of a control on a
subform, I would ask the user if they'd like to have their change affect other
records in the same subform...if YES, then run the target SQL statement, and
refresh the subform so the user could see the changes.

The truly maddening part is that it was intermittent... sometimes it would work,
and sometimes it wouldn't. Some machines would never fail on dbs.Execute.
RunSQL made it work for all machine at all times.

dbs is dimensioned as a Global Variable (DAO.Database), and it is set to
Currentdb in the line before the Execute method.

dbs.Execute is used w/o incident elsewhere in the application.

When running line-by-line in debug mode, everything worked great until the
..Execute method...crasho la. If I were to take the SQL statement and run it from
the query window, it would work, even in debug mode.

CONCLUSION: Something's fishy about the dbs reference during runtime in this
context. The code is similar to the following:

Sub Control_AfterUp date
If Control.OldValu e <> Control.Value Then
If vbYes = MsgBox("Cascade ") Then
strSQL = "UPDATE TableBoundToSub form SET TargetField = ...blah"
Set dbs = Currentdb
dbs.Execute dbfailonerror
End if
End if
End Sub

One more thing: I have code like above on two separate controls in the same
subform. One of the SQL statements was complex enough that I decided to make a
paramterized Action query out of it, so it's code:

Sub Control_AfterUp date
If Control.OldValu e <> Control.Value Then
If vbYes = MsgBox("Cascade ") Then
Set dbs = Currentdb
With dbs.QueryDefs(" MyQDF")
.Parameters("P1 ") = Me.Field1
.Parameters("P2 ") = me.Field2
.Execute dbfailonerror
End With
End if
End if
End Sub

That also fails on the Execute method. When I changed both to:

Sub Control_AfterUp date
If Control.OldValu e <> Control.Value Then
If vbYes = MsgBox("Cascade ") Then
strSQL = "UPDATE TableBoundToSub form SET TargetField = ...blah"
DoCmd.SetWarnin gs False
Docmd.RunSQL strSQL, True
DoCmd.SetWarnin gs True
End if
End if
End Sub

....everything works as expected.

Any thoughts?
Nov 12 '05 #1
21 2527
On 01 May 2004 06:23:05 GMT, DCM Fan wrote:
[...]
Bottom line: In a certain context dbs.Execute strSQL, dbfailonerror would cause
Access to GPF, whilst DoCmd.RunSQL strSQL, True would perform as expected.
[...]

Any thoughts?


/decompile ?

Peter

--
No mails please.
Nov 12 '05 #2
On 01 May 2004 06:23:05 GMT, dc****@aol.comSPNOAM (DCM Fan) wrote:
Access 2000/Windows 2000 Pro with all current updates on the client; SQL Server
7.0/Windows 2000 Server with all current updates on the server.

Bottom line: In a certain context dbs.Execute strSQL, dbfailonerror would cause
Access to GPF, whilst DoCmd.RunSQL strSQL, True would perform as expected.

The context is nothing special, but MUST have something to do with it, even
though I've done this 1000X before. In the AfterUpdate Event of a control on a
subform, I would ask the user if they'd like to have their change affect other
records in the same subform...if YES, then run the target SQL statement, and
refresh the subform so the user could see the changes.

The truly maddening part is that it was intermittent... sometimes it would work,
and sometimes it wouldn't. Some machines would never fail on dbs.Execute.
RunSQL made it work for all machine at all times.

dbs is dimensioned as a Global Variable (DAO.Database), and it is set to
Currentdb in the line before the Execute method.

dbs.Execute is used w/o incident elsewhere in the application.

When running line-by-line in debug mode, everything worked great until the
.Execute method...crasho la. If I were to take the SQL statement and run it from
the query window, it would work, even in debug mode.

CONCLUSION: Something's fishy about the dbs reference during runtime in this
context. The code is similar to the following:

Sub Control_AfterUp date
If Control.OldValu e <> Control.Value Then
If vbYes = MsgBox("Cascade ") Then
strSQL = "UPDATE TableBoundToSub form SET TargetField = ...blah"
Set dbs = Currentdb
dbs.Execute dbfailonerror
End if
End if
End Sub

One more thing: I have code like above on two separate controls in the same
subform. One of the SQL statements was complex enough that I decided to make a
paramterized Action query out of it, so it's code:

Sub Control_AfterUp date
If Control.OldValu e <> Control.Value Then
If vbYes = MsgBox("Cascade ") Then
Set dbs = Currentdb
With dbs.QueryDefs(" MyQDF")
.Parameters("P1 ") = Me.Field1
.Parameters("P2 ") = me.Field2
.Execute dbfailonerror
End With
End if
End if
End Sub

That also fails on the Execute method. When I changed both to:

Sub Control_AfterUp date
If Control.OldValu e <> Control.Value Then
If vbYes = MsgBox("Cascade ") Then
strSQL = "UPDATE TableBoundToSub form SET TargetField = ...blah"
DoCmd.SetWarnin gs False
Docmd.RunSQL strSQL, True
DoCmd.SetWarnin gs True
End if
End if
End Sub

...everythin g works as expected.

Any thoughts?


I don't know if this helps, but....

I had a very similar problem today. I was helping a colleague debug a problem
with a query that used to work and recently started failing. He had added a
criterion to the query that compared a field to a function call that returns
the current company ID, and the comparison was on a left-joined table. His
change wouldn't have worked right anyway because the purpose of the left join
was to check for a mismatch, and applying a criterion to the left-joined table
made it act like an inner join. It still should not have produced an error,
though.

To fix this, I created a separate querydef to return just the records from the
secondary table that apply to the current company, then changed the original
query to left-join to the new query. I could have made it a derived table
using [...]. As <name> syntax, but I thought a separate saved query would be
more clear.

Before making this change, the error message was something like "Unknown JET
Error.". After the change, everything behaved as it should.
Nov 12 '05 #3
Have you checked carefully that your query is executing correctly under
RunSQL?
Turning off the warnings is leaving open the possibility that it's quietly
failing and just not letting you know.
(You might get the same effect if you dropped dbfailonerror from your code.)

I'd suggest that you try removing SetWarnings around the RunSQL.
Yes, you'll have to accept a few more messageboxes when it runs, but you may
get a useful error message when it fails.
Once you can see what the problem is, you'll be in a better position to
address it.

HTH
- Turtle

"DCM Fan" <dc****@aol.com SPNOAM> wrote in message
news:20******** *************** ****@mb-m01.aol.com...
Access 2000/Windows 2000 Pro with all current updates on the client; SQL Server 7.0/Windows 2000 Server with all current updates on the server.

Bottom line: In a certain context dbs.Execute strSQL, dbfailonerror would cause Access to GPF, whilst DoCmd.RunSQL strSQL, True would perform as expected.

The context is nothing special, but MUST have something to do with it, even though I've done this 1000X before. In the AfterUpdate Event of a control on a subform, I would ask the user if they'd like to have their change affect other records in the same subform...if YES, then run the target SQL statement, and refresh the subform so the user could see the changes.

The truly maddening part is that it was intermittent... sometimes it would work, and sometimes it wouldn't. Some machines would never fail on dbs.Execute.
RunSQL made it work for all machine at all times.

dbs is dimensioned as a Global Variable (DAO.Database), and it is set to
Currentdb in the line before the Execute method.

dbs.Execute is used w/o incident elsewhere in the application.

When running line-by-line in debug mode, everything worked great until the
.Execute method...crasho la. If I were to take the SQL statement and run it from the query window, it would work, even in debug mode.

CONCLUSION: Something's fishy about the dbs reference during runtime in this context. The code is similar to the following:

Sub Control_AfterUp date
If Control.OldValu e <> Control.Value Then
If vbYes = MsgBox("Cascade ") Then
strSQL = "UPDATE TableBoundToSub form SET TargetField = ...blah"
Set dbs = Currentdb
dbs.Execute dbfailonerror
End if
End if
End Sub

One more thing: I have code like above on two separate controls in the same subform. One of the SQL statements was complex enough that I decided to make a paramterized Action query out of it, so it's code:

Sub Control_AfterUp date
If Control.OldValu e <> Control.Value Then
If vbYes = MsgBox("Cascade ") Then
Set dbs = Currentdb
With dbs.QueryDefs(" MyQDF")
.Parameters("P1 ") = Me.Field1
.Parameters("P2 ") = me.Field2
.Execute dbfailonerror
End With
End if
End if
End Sub

That also fails on the Execute method. When I changed both to:

Sub Control_AfterUp date
If Control.OldValu e <> Control.Value Then
If vbYes = MsgBox("Cascade ") Then
strSQL = "UPDATE TableBoundToSub form SET TargetField = ...blah"
DoCmd.SetWarnin gs False
Docmd.RunSQL strSQL, True
DoCmd.SetWarnin gs True
End if
End if
End Sub

...everything works as expected.

Any thoughts?

Nov 12 '05 #4
<</decompile ?>>

Been there, done that.

<<the error message was something like "Unknown JET Error.". >>

I wish I had that opportunity...A ccess would GPF...no error messages. And
besides, the query worked when run manually.

<<Have you checked carefully that your query is executing correctly under
RunSQL?>>

Of course I did!
Nov 12 '05 #5
On May 01 2004, 02:23 am, dc****@aol.comSPNOAM (DCM Fan) wrote in
news:20******** *************** ****@mb-m01.aol.com:
Bottom line: In a certain context dbs.Execute strSQL, dbfailonerror
would cause Access to GPF, whilst DoCmd.RunSQL strSQL, True would
perform as expected.


You may try to change it to

dbs.Execute strSQL, dbfailonerror + dbSeeChanges

Technically, you want to always do it this way when you are using DAO to
work with SQL Server backend.

I have no idea if this has any relevance to your posted issue.

--
remove a 9 to reply by email
Nov 12 '05 #6
>CONCLUSION: Something's fishy about the dbs reference during runtime in
this
context. The code is similar to the following:

did you ever stop to ask the following question?

How does sql server, or MySql or any database engine evaluate the following:

DoCmd.RunSQL "update main set notes = 'hello' where City =
forms!main!Upda teCity"

Ask your self why does the above not test for City = "forms!main!Cit y" but
in fact somehow magically converts the "forms!main!tva lue" to the actual
value? Sql server can't do this. Oracle can't do the above. Yet, we can use
both Oracle, or sql server with ms-access. So, how can the above be
possible?

It is question that should leap out at you!

The fact is that RunSql uses the JET expression service. The expression
service is a thing that runs and evaluates expression in the sql BEFORE the
query is processed. I mean, I never seen sql for Oracle, or MySql, or even
sql server allow expressions like:

where City = forms!main!Upda teCity"

So, when you use currentDB.Execu te, you DO NOT have the expression service
available. That means you can't use a forms ref directly in the sql
(gee...what a mess in the fact that we CAN do this!). I would suggest that
you avoid using ANY sql that has a forms ref. It is simply not needed during
development. Worse, it means your sql or query is now tied to some form that
has to be opened..and if closed..the query will fail. And, even more worse
is that you can NOT use the sql query for other things..as it is tied to ONE
form that must be opened (so, you get very poor re-usability)

So, the following will work:
'
DoCmd.RunSQL "update main set notes = 'hello' where City =
forms!main!Upda teCity"

However, for Execute..we need to use:

currentDB.Execu te "update main set notes = 'hello' where City = '" &
forms!main!Upda teCity & "'"
I also notice that in your posted example you for strange and bizarre reason
left out the sql! I mean here you are wondering about a problem with
sql..and then you post a whole bunch of code...but then leave out the sql?
(not a big deal..but then we could have spotted the fact that you use direct
forms refs in your sql).

Anyway..likely you have some sql that requites the expression service to
resolve some value to a form, or some function..and that is not a good idea
at all..

Further, why use a global var set to currentdb? If any error occurs that you
don't trap..then that var is going to be destroyed..and then any code you
try to run will fail.

--
Albert D. Kallal (MVP)
Edmonton, Alberta Canada
pl************* *****@msn.com
http://www.attcanada.net/~kallal.msn

Nov 12 '05 #7
<,How does sql server, or MySql or any database engine evaluate the following:

DoCmd.RunSQL "update main set notes = 'hello' where City =
forms!main!Upda teCity">>

You're joking, right? Do actually think that I have an embedded form reference
in a SQL statement? Did you read the entire original post, where I clearly
showed that I create the SQL statement in-process (in a strSQL variable),
before the call to dbs.execute, and where I said that the SQL statement
evaluates properly and can be run when pasted into the query window?
(TRANSLATION: It's not the SQL statement)

<<I also notice that in your posted example you for strange and bizarre reason
left out the sql! >>

Yes, b/c the SQL is NOT the problem! Recall in the original post that I also
used a parameterized QueryDef as well...with the same problem. (TRANSLATION:
Not the SQL statement)

<<If any error occurs that you don't trap..then that var is going to be
destroyed..and then any code you
try to run will fail.>>

An error would be great, and my error-trap would've caught it, but I clearly
stated in the message that this was a crash...GPF in fact. (TRANSLATION: Not
the SQL statement)

Anyway, a previous poster did give me something useful to try, and I should've
tried it before: using the dbSeeChanges constant with dbFailOnError. Normally,
Access complains about this when I leave it off, but it's not right now...just
crashing. I bet that's the problem, and I should know better. It's certainly
not the SQL statement!

Thanks anyway!
Nov 12 '05 #8
<<dbs.Execute strSQL, dbfailonerror + dbSeeChanges

Technically, you want to always do it this way when you are using DAO to
work with SQL Server backend.

I have no idea if this has any relevance to your posted issue.>>

Right on! I need to do that! I forgot all about this, b/c Access normall
complains with a pretty straight-forward message (You must use dbSeeChanges
when connecting to ...) but it didn't this time...just crashed.

I'm sure this will solve the problem.

Thanks.
Nov 12 '05 #9
dc****@aol.comSPNOAM (DCM Fan) wrote in
news:20******** *************** ****@mb-m01.aol.com:
Sub Control_AfterUp date
If Control.OldValu e <> Control.Value Then
If vbYes = MsgBox("Cascade ") Then
strSQL = "UPDATE TableBoundToSub form SET TargetField =
...blah" Set dbs = Currentdb
dbs.Execute dbfailonerror
End if
End if
End Sub


I can't really offer any advice for your problem, but I will observe
this, on the assumption that your air code example above is not
wholly divorced from the reality of your situation:

What I see is that you're using the AfterUpdate of a bound control
to update a table that is bound to an open form. I won't assume that
the bound control you're testing is bound to the same table as
you're updating with SQL, but if it's one of the other open forms
(my guess is that the control is on the parent form and you're using
SQL to update the subform's records), perhaps that form is dirty,
and there's a lock on the records and that's causing an error that
Access is not recovering from (granted, it shouldn't IPF).

I just don't see a need for the kind of operation your example uses.
If all the records in the subform need to be updated, then use the
control that you're updating as part of the link criteria.

Also, don't disregard Turtle's note about testing with SetWarnings
on, as some error may be occuring that is being discarded in your
RunSQL context, but not in the .Execute context, and the attempt to
handle that error is what is leading to the IPF.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
8237
by: Jim | last post by:
I am using Access 97 on a PC running Windows NT 4.0 SP6a. I have some code (shown below) intended to add a set of records to one table (tblGradeProps) when a new record is created in another (tblGrades) The oddity is that when the procedure Detail_Click is called from the procedure cmbMktSect_Exit, the RunSQL statement doesn't add the required records but it does so when invoked by the Detail_Click event!
4
10186
by: Rotsj | last post by:
Hi, i try to execute an update query from within a form, but i get the message: run time error '3144'. Syntax error on the update statement when i try something like this: DoCmd.RunSQL "UPDATE tblKlant " & _ "SET tblKlant.Bedrag = tblKlant.Bedrag + 10.96" & _ " WHERE tblKlant. = forms!!"
19
424
by: DCM Fan | last post by:
Access 2000/Windows 2000 Pro with all current updates on the client; SQL Server 7.0/Windows 2000 Server with all current updates on the server. Bottom line: In a certain context dbs.Execute strSQL, dbfailonerror would cause Access to GPF, whilst DoCmd.RunSQL strSQL, True would perform as expected. The context is nothing special, but MUST have something to do with it, even though I've done this 1000X before. In the AfterUpdate Event of a...
3
3454
by: Pathfinder | last post by:
Hi All I am trying to run the below but I receive the following error "runsql action requires an argument consisting of an SQL statment" Dim MySQL$ MySQL$ = "Select * from mytablename" DoCmd.RunSQL MySQL$ Any reason for that
7
4283
by: Richard Hollenbeck | last post by:
Help! I don't know why this isn't working: Private Sub Combo9_Change() Dim UsersCourseSelection As String UsersCourseSelection = Me("Combo9").Value Combo13.Visible = True 'the following SQL thing is all on one line in the actual code.
2
5702
by: ben | last post by:
I have the following code in a VBA module: DoCmd.RunSql "Update tData Set sd = Log(Strike/Price) where symbol = '" & symbol & "'" This statement worked fine, and was using the built in math Log function. In a separate module, I added the following function:
8
2778
by: paulwilliamsonremove | last post by:
Hi, Using Access 2003. I am trying to delete records from one table/query ("qryHistoryPersonIDs") if they don't exist in another table ("qryDonations"). But the SQL syntax I came up with is taking forever or locking up Access 2003. What am I doing wrong?
2
2808
by: Umoja | last post by:
Hi guys, Currently in my DB I have a macro to run an Sql action, I am using the INSERT INTO function. Everything is working fine but I wanted to increase the number of fields that is being entered into the table. In Access the run sql action only accepts up to 256 characters. I decided maybe it can be done by setting up 2 RunSql actions. The problem I am having is the second RunSql action is not entering the data on the same row as the first...
0
8259
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8192
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8696
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8637
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8502
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7188
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5571
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4090
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1504
bsmnconsultancy
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.