There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen blue screen blue screen of death boot bsod computer connection crash css dell display driver drivers email error excel firefox firefox 3 hard drive internet internet explorer itunes laptop linux malware monitor network networking outlook outlook 2003 outlook express partition password printer problem problems ram router security slow sound trojan usb video virus vista windows windows xp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
How can I test an sql statement before applying it to a query?


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
wango's Avatar
Member with 74 posts.
 
Join Date: Nov 2001
Location: Silver 'Spring
28-Aug-2002, 04:58 PM #1
How can I test an sql statement before applying it to a query?
How can I test an sql statement before applying it to a query:
The reason I am asking this question is the following:

I am trying to change the query “QryOGCGeneric” programmatically.
If I send in a correct query (txtSQL = “Select * from tblAGENCY”)
Everything is ok.
The moment I send in wrong query (txtSQL = “Select * from tblAGENCIES”)

I get an error: “Item cannot be found in the collection corresponding to the requested name or ordinal”

This error will still come regardless of whether I send in a correct
SQL statement thereafter or not.

Using:
Private Function IsQueryGood() As Boolean

Does not work either.

Private Function PopulateQry(boolDisplayQry As Boolean)

Dim strSQL As String
Dim strSQL1 As String

'Set a reference for Microsoft ADO Ext. 2.1
'for DDL and security.
Dim cat As ADOX.Catalog
Dim cmd As ADODB.Command
'Dim vwu As ADOX.View

On Error GoTo PopulateQryErr

Set cat = New ADOX.Catalog
cat.ActiveConnection = CurrentProject.Connection

'If TypeOfQuery("QryOGCGeneric") = "View" Then
'txtSQL has already been validated

Set cmd = cat.Views("QryOGCGeneric").Command

cmd.CommandText = txtSQL
Set cat.Views("QryOGCGeneric").Command = cmd
cat.Views.Refresh

Set cat = Nothing
Set cmd = Nothing


Exit_This:
On Error GoTo 0
Exit Function

PopulateQryErr:
MsgBox Err.Description

MsgBox "Error " & Err.Number & " " & Err.Description & vbCrLf & _
" Most likely a wrong query", vbCritical, "OGC"

Set cat = Nothing
Set cmd = Nothing

Resume Exit_This

End Function

Private Function IsQueryGood() As Boolean

On Error GoTo HandleErr


'DoCmd.OpenQuery strQueryName, acViewNormal

IsQueryGood = False

' Test the sql statement first
DoCmd.RunSQL txtSQL

IsQueryGood = True

ExitHere:
Exit Function

' Error handling block added by Error Handler Add-In. DO NOT EDIT this block of code.
' Automatic error handler last updated at 10-02-2001 11:50:10 'ErrorHandler:$$D=10-02-2001 'ErrorHandler:$$T=11:50:10
HandleErr:
Select Case Err.Number
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "UtilityFunctions.OpenQueryAndWait" 'ErrorHandler:$$N=UtilityFunctions.OpenQueryAndWait
End Select
' End Error handling block.
End Function
__________________
Wango
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 10:15 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.