PC Review


Reply
 
 
=?Utf-8?B?RGlvZ28=?=
Guest
Posts: n/a
 
      31st Jul 2007
Public Function Comando001_Click()

Dim mySQL As String

mySQL = "SELECT Numerario.Numerario FROM Numerario WHERE
(((Numerario.Data)=Date()))"

DoCmd.RunSQL mySQL

If mySQL = Null Then

DoCmd.SetWarnings WarningsOff
DoCmd.OpenQuery "append_numerario"

End If

End Function

Ok I was trying to use this code to run a query based on another query, but
it stops and says: "run-time error '2342'
A RunSQL action requires an argument consisting of an SQL statement"

Could someone help please?


 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      1st Aug 2007
In news:2B3D51C8-240C-4FE2-B80E-(E-Mail Removed),
Diogo <(E-Mail Removed)> wrote:
> Public Function Comando001_Click()
>
> Dim mySQL As String
>
> mySQL = "SELECT Numerario.Numerario FROM Numerario WHERE
> (((Numerario.Data)=Date()))"
>
> DoCmd.RunSQL mySQL
>
> If mySQL = Null Then
>
> DoCmd.SetWarnings WarningsOff
> DoCmd.OpenQuery "append_numerario"
>
> End If
>
> End Function
>
> Ok I was trying to use this code to run a query based on another
> query, but it stops and says: "run-time error '2342'
> A RunSQL action requires an argument consisting of an SQL statement"
>
> Could someone help please?


You can only use RunSQL with action queries, such as append, delete, and
make-table queries. You're trying to use it with a select query, to
look up a value. That doesn't work, though the error message is
confusing.

If your intention is to find out if there are any records for today in
the table or query, "Numerario", you *could* open a recordset on your
SELECT statement, but it's probably easier just to use the DLookup
function:

If IsNull(DLookup("Numerario", "Numerario", "[Data]=Date()")) Then
DoCmd.SetWarnings False
DoCmd.OpenQuery "append_numerario"
DoCmd.SetWarnings True
End If

The above code will execute "append_numerario" only if there are no
matching records -- so long as the field Numerario can never have a Null
value.

Another alternative would be to use DCount:

If DCount("*", "Numerario", "[Data]=Date()") = 0 Then
DoCmd.SetWarnings False
DoCmd.OpenQuery "append_numerario"
DoCmd.SetWarnings True
End If

I prefer not to use SetWarnings, though, so I'd replace this:

DoCmd.SetWarnings False
DoCmd.OpenQuery "append_numerario"
DoCmd.SetWarnings True

with this:

CurrentDb.Execute "append_numerario"

That's assuming the "append_numerario" is an action query, not a select
query whose output you want to see in a datasheet.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
=?Utf-8?B?SmltIEJ1cmtlIGluIE5vdmk=?=
Guest
Posts: n/a
 
      1st Aug 2007
I think Dirk is right, but in your criteria you may need to specify your date
criteria as "[Data] = #" & Date() & "#".

"Dirk Goldgar" wrote:

> In news:2B3D51C8-240C-4FE2-B80E-(E-Mail Removed),
> Diogo <(E-Mail Removed)> wrote:
> > Public Function Comando001_Click()
> >
> > Dim mySQL As String
> >
> > mySQL = "SELECT Numerario.Numerario FROM Numerario WHERE
> > (((Numerario.Data)=Date()))"
> >
> > DoCmd.RunSQL mySQL
> >
> > If mySQL = Null Then
> >
> > DoCmd.SetWarnings WarningsOff
> > DoCmd.OpenQuery "append_numerario"
> >
> > End If
> >
> > End Function
> >
> > Ok I was trying to use this code to run a query based on another
> > query, but it stops and says: "run-time error '2342'
> > A RunSQL action requires an argument consisting of an SQL statement"
> >
> > Could someone help please?

>
> You can only use RunSQL with action queries, such as append, delete, and
> make-table queries. You're trying to use it with a select query, to
> look up a value. That doesn't work, though the error message is
> confusing.
>
> If your intention is to find out if there are any records for today in
> the table or query, "Numerario", you *could* open a recordset on your
> SELECT statement, but it's probably easier just to use the DLookup
> function:
>
> If IsNull(DLookup("Numerario", "Numerario", "[Data]=Date()")) Then
> DoCmd.SetWarnings False
> DoCmd.OpenQuery "append_numerario"
> DoCmd.SetWarnings True
> End If
>
> The above code will execute "append_numerario" only if there are no
> matching records -- so long as the field Numerario can never have a Null
> value.
>
> Another alternative would be to use DCount:
>
> If DCount("*", "Numerario", "[Data]=Date()") = 0 Then
> DoCmd.SetWarnings False
> DoCmd.OpenQuery "append_numerario"
> DoCmd.SetWarnings True
> End If
>
> I prefer not to use SetWarnings, though, so I'd replace this:
>
> DoCmd.SetWarnings False
> DoCmd.OpenQuery "append_numerario"
> DoCmd.SetWarnings True
>
> with this:
>
> CurrentDb.Execute "append_numerario"
>
> That's assuming the "append_numerario" is an action query, not a select
> query whose output you want to see in a datasheet.
>
> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com
>
> (please reply to the newsgroup)
>
>
>

 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      1st Aug 2007
And you should explicitly set the format, since Access doesn't respect
Regional Settings in queries:

"[Data] = #" & Format(Date(), "\yyyy\-mm\-dd") & "#"



--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Jim Burke in Novi" <(E-Mail Removed)> wrote in
message news:C27A1DD7-A0ED-443E-8196-(E-Mail Removed)...
>I think Dirk is right, but in your criteria you may need to specify your
>date
> criteria as "[Data] = #" & Date() & "#".
>
> "Dirk Goldgar" wrote:
>
>> In news:2B3D51C8-240C-4FE2-B80E-(E-Mail Removed),
>> Diogo <(E-Mail Removed)> wrote:
>> > Public Function Comando001_Click()
>> >
>> > Dim mySQL As String
>> >
>> > mySQL = "SELECT Numerario.Numerario FROM Numerario WHERE
>> > (((Numerario.Data)=Date()))"
>> >
>> > DoCmd.RunSQL mySQL
>> >
>> > If mySQL = Null Then
>> >
>> > DoCmd.SetWarnings WarningsOff
>> > DoCmd.OpenQuery "append_numerario"
>> >
>> > End If
>> >
>> > End Function
>> >
>> > Ok I was trying to use this code to run a query based on another
>> > query, but it stops and says: "run-time error '2342'
>> > A RunSQL action requires an argument consisting of an SQL statement"
>> >
>> > Could someone help please?

>>
>> You can only use RunSQL with action queries, such as append, delete, and
>> make-table queries. You're trying to use it with a select query, to
>> look up a value. That doesn't work, though the error message is
>> confusing.
>>
>> If your intention is to find out if there are any records for today in
>> the table or query, "Numerario", you *could* open a recordset on your
>> SELECT statement, but it's probably easier just to use the DLookup
>> function:
>>
>> If IsNull(DLookup("Numerario", "Numerario", "[Data]=Date()")) Then
>> DoCmd.SetWarnings False
>> DoCmd.OpenQuery "append_numerario"
>> DoCmd.SetWarnings True
>> End If
>>
>> The above code will execute "append_numerario" only if there are no
>> matching records -- so long as the field Numerario can never have a Null
>> value.
>>
>> Another alternative would be to use DCount:
>>
>> If DCount("*", "Numerario", "[Data]=Date()") = 0 Then
>> DoCmd.SetWarnings False
>> DoCmd.OpenQuery "append_numerario"
>> DoCmd.SetWarnings True
>> End If
>>
>> I prefer not to use SetWarnings, though, so I'd replace this:
>>
>> DoCmd.SetWarnings False
>> DoCmd.OpenQuery "append_numerario"
>> DoCmd.SetWarnings True
>>
>> with this:
>>
>> CurrentDb.Execute "append_numerario"
>>
>> That's assuming the "append_numerario" is an action query, not a select
>> query whose output you want to see in a datasheet.
>>
>> --
>> Dirk Goldgar, MS Access MVP
>> www.datagnostics.com
>>
>> (please reply to the newsgroup)
>>
>>
>>



 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      1st Aug 2007
In news:C27A1DD7-A0ED-443E-8196-(E-Mail Removed),
Jim Burke in Novi <(E-Mail Removed)> wrote:
> I think Dirk is right, but in your criteria you may need to specify
> your date criteria as "[Data] = #" & Date() & "#".


You don't have to do that if you embed the reference to the Date()
function in the criteria argument itself, as I showed. The DLookup
function *will* work that way. If you want to embed the literal date
value in the criteria string, then you have to use the "#" marks and
format it unambiguously, as you and Doug have pointed out.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
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
Stop a query =?Utf-8?B?RGlvZ28=?= Microsoft Access Queries 0 31st Jul 2007 12:50 AM
How do I tell an update query to do until it should stop!! =?Utf-8?B?U2lkeg==?= Microsoft Access Queries 2 14th Apr 2006 01:50 AM
stop web query =?Utf-8?B?SmVyZW15IEJlcnRvbWV1?= Microsoft Excel Programming 2 19th Jun 2005 01:31 AM
Stop to modify the SQL query manually entered into query ! =?Utf-8?B?T2xpdmllciBSb2xsZXQ=?= Microsoft Excel Programming 6 3rd Nov 2004 09:34 AM
How to stop the query processing Fred Fortin Microsoft Access Queries 3 17th Nov 2003 02:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:30 AM.