PC Review


Reply
Thread Tools Rate Thread

docmd.runsql = Access 2002

 
 
=?Utf-8?B?QlMgR2FsYWN0aWNh?=
Guest
Posts: n/a
 
      8th Mar 2005
I'm working on a DB in MS 2002. Below is the code. Basically the
Docmd.RunSQL is not working. I can paste the SQL string into a query and it
works just fine. Has anyone had this problem? Please let me know if you see
anything odd. Thanks.

CODE:

Dim strQry As String
Dim strFLT As String
Dim strORD As String


strQry = "SELECT [DNIL_DNIL_MAIN].[CSCI] & [DNIL_DNIL_MAIN].[DNIL_TYPE]
& [DNIL_DNIL_MAIN].[DNIL_NUMBER] AS ID, DNIL_DNIL_MAIN.STATUS,
DNIL_DNIL_MAIN.SUBSYSTEM, DNIL_DNIL_MAIN.PRIORITY,
DNIL_DNIL_MAIN.DESCRIPTION, DNIL_DNIL_OP_IMPACT.OP_IMPACT,
DNIL_DNIL_OP_IMPACT.HOW_TO_TEST, DNIL_DNIL_MAIN.PROGRAM,
DNIL_DNIL_MAIN.PROJECT_NAME FROM DNIL_DNIL_MAIN LEFT JOIN DNIL_DNIL_OP_IMPACT
ON DNIL_DNIL_MAIN.DNIL_NUMBER = DNIL_DNIL_OP_IMPACT.DNIL_NUMBER"

strORD = " ORDER BY [DNIL_DNIL_MAIN].[CSCI] &
[DNIL_DNIL_MAIN].[DNIL_TYPE] & [DNIL_DNIL_MAIN].[DNIL_NUMBER]"

If Me!cboProgram <> "" Then
strFLT = " WHERE [DNIL_DNIL_MAIN].[PROGRAM] = '" & Me!cboProgram &
"' "
ElseIf Me!cboProject <> "" Then
strFLT = " WHERE [DNIL_DNIL_MAIN].[PROJECT_NAME] = '" &
Me!cboProject & "' "
Else
'give them all programs and projects
strFLT = ""
End If

'MsgBox (strFLT)

strQry = strQry & strFLT & strORD & ";"
'MsgBox (strQry)
DoCmd.RunSQL strQry
 
Reply With Quote
 
 
 
 
Ken Snell [MVP]
Guest
Posts: n/a
 
      8th Mar 2005
DoCmd.RunSQL is used to run an action query (update, delete, maketable) or a
data-definition query. It will not run a select query, which is what you're
trying to do here.

What are you wanting to do with this query when you "run" it in code?

--

Ken Snell
<MS ACCESS MVP>


"BS Galactica" <(E-Mail Removed)> wrote in message
news:BA2AF5B1-CB6B-4614-95C3-(E-Mail Removed)...
> I'm working on a DB in MS 2002. Below is the code. Basically the
> Docmd.RunSQL is not working. I can paste the SQL string into a query and
> it
> works just fine. Has anyone had this problem? Please let me know if you
> see
> anything odd. Thanks.
>
> CODE:
>
> Dim strQry As String
> Dim strFLT As String
> Dim strORD As String
>
>
> strQry = "SELECT [DNIL_DNIL_MAIN].[CSCI] & [DNIL_DNIL_MAIN].[DNIL_TYPE]
> & [DNIL_DNIL_MAIN].[DNIL_NUMBER] AS ID, DNIL_DNIL_MAIN.STATUS,
> DNIL_DNIL_MAIN.SUBSYSTEM, DNIL_DNIL_MAIN.PRIORITY,
> DNIL_DNIL_MAIN.DESCRIPTION, DNIL_DNIL_OP_IMPACT.OP_IMPACT,
> DNIL_DNIL_OP_IMPACT.HOW_TO_TEST, DNIL_DNIL_MAIN.PROGRAM,
> DNIL_DNIL_MAIN.PROJECT_NAME FROM DNIL_DNIL_MAIN LEFT JOIN
> DNIL_DNIL_OP_IMPACT
> ON DNIL_DNIL_MAIN.DNIL_NUMBER = DNIL_DNIL_OP_IMPACT.DNIL_NUMBER"
>
> strORD = " ORDER BY [DNIL_DNIL_MAIN].[CSCI] &
> [DNIL_DNIL_MAIN].[DNIL_TYPE] & [DNIL_DNIL_MAIN].[DNIL_NUMBER]"
>
> If Me!cboProgram <> "" Then
> strFLT = " WHERE [DNIL_DNIL_MAIN].[PROGRAM] = '" & Me!cboProgram &
> "' "
> ElseIf Me!cboProject <> "" Then
> strFLT = " WHERE [DNIL_DNIL_MAIN].[PROJECT_NAME] = '" &
> Me!cboProject & "' "
> Else
> 'give them all programs and projects
> strFLT = ""
> End If
>
> 'MsgBox (strFLT)
>
> strQry = strQry & strFLT & strORD & ";"
> 'MsgBox (strQry)
> DoCmd.RunSQL strQry



 
Reply With Quote
 
=?Utf-8?B?JzY5IENhbWFybw==?=
Guest
Posts: n/a
 
      8th Mar 2005
Hi.

The DoCmd.RunSQL method only works with action queries. A SELECT statement
isn't an action query. That's why it works with the regular query, but not
in VBA code.

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)

- - -
When you see correct answers to your question posted in Microsoft's Online
Community, please sign in to the Community and mark these posts, so that all
may benefit by filtering on "Answered questions" and quickly finding the
right answers to similar questions. Remember that the best answers are often
given to those who have a history of rewarding the contributors who have
taken the time to answer questions correctly.


"BS Galactica" wrote:

> I'm working on a DB in MS 2002. Below is the code. Basically the
> Docmd.RunSQL is not working. I can paste the SQL string into a query and it
> works just fine. Has anyone had this problem? Please let me know if you see
> anything odd. Thanks.
>
> CODE:
>
> Dim strQry As String
> Dim strFLT As String
> Dim strORD As String
>
>
> strQry = "SELECT [DNIL_DNIL_MAIN].[CSCI] & [DNIL_DNIL_MAIN].[DNIL_TYPE]
> & [DNIL_DNIL_MAIN].[DNIL_NUMBER] AS ID, DNIL_DNIL_MAIN.STATUS,
> DNIL_DNIL_MAIN.SUBSYSTEM, DNIL_DNIL_MAIN.PRIORITY,
> DNIL_DNIL_MAIN.DESCRIPTION, DNIL_DNIL_OP_IMPACT.OP_IMPACT,
> DNIL_DNIL_OP_IMPACT.HOW_TO_TEST, DNIL_DNIL_MAIN.PROGRAM,
> DNIL_DNIL_MAIN.PROJECT_NAME FROM DNIL_DNIL_MAIN LEFT JOIN DNIL_DNIL_OP_IMPACT
> ON DNIL_DNIL_MAIN.DNIL_NUMBER = DNIL_DNIL_OP_IMPACT.DNIL_NUMBER"
>
> strORD = " ORDER BY [DNIL_DNIL_MAIN].[CSCI] &
> [DNIL_DNIL_MAIN].[DNIL_TYPE] & [DNIL_DNIL_MAIN].[DNIL_NUMBER]"
>
> If Me!cboProgram <> "" Then
> strFLT = " WHERE [DNIL_DNIL_MAIN].[PROGRAM] = '" & Me!cboProgram &
> "' "
> ElseIf Me!cboProject <> "" Then
> strFLT = " WHERE [DNIL_DNIL_MAIN].[PROJECT_NAME] = '" &
> Me!cboProject & "' "
> Else
> 'give them all programs and projects
> strFLT = ""
> End If
>
> 'MsgBox (strFLT)
>
> strQry = strQry & strFLT & strORD & ";"
> 'MsgBox (strQry)
> DoCmd.RunSQL strQry

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What Do You Use Instead of DoCmd.OpenQuery or DoCmd.RunSQL Mr. JYC Microsoft Access VBA Modules 2 30th Sep 2008 07:31 PM
docmd.runsql =?Utf-8?B?U3RldmUnbw==?= Microsoft Access VBA Modules 1 27th Jun 2005 02:56 PM
DoCmd.RunSQL taccea Microsoft Access 2 16th Nov 2004 03:32 AM
Re: DoCmd.RunSQL in VB Dirk Goldgar Microsoft Access 10 30th Aug 2004 10:59 PM
DoCmd.RunSQL Jim Microsoft Access 1 10th Sep 2003 04:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:52 PM.