Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - VBScript problem in running Stored Query

Reply
 
Old 09-18-2008   #1 (permalink)
Codeblack


 
 

VBScript problem in running Stored Query

I am having strange problem. I have a saved query in MS Access which works
absolutely fine without any problems. But when I try to call the stored query
from VBScript I get the below error. In fact the database has records in it.
Can anyone tell me what could be the problem. Any help will be greatly
appreciated

*******************************************
Error
Either BOF or EOF is True, or the current record has been deleted.

*************************************************
MS Access Query

SELECT SenderToRecip.Sender, AllEmployees.DeptCode, AllEmployees.Department,
AllEmployees.City, SenderToRecip.Recipient, Sum([Total_Bytes]/1024/1024) AS
Total_MB, Sum(SenderToRecip.Recip_Counts) AS Recip_Counts FROM
[Corp009d-Skip] INNER JOIN (SenderToRecip INNER JOIN
AllEmployees ON SenderToRecip.Sender=AllEmployees.Email) ON
([Corp009d-Skip].recipient=SenderToRecip.Recipient) AND
([Corp009d-Skip].sender=SenderToRecip.Sender)
WHERE
(((InStr(Left(SenderToRecip.Recipient,InStr(SenderToRecip.Recipient,"@")-1),[LName]))>0))
GROUP BY SenderToRecip.Sender, AllEmployees.DeptCode,
AllEmployees.Department, AllEmployees.City, SenderToRecip.Recipient
HAVING (((SenderToRecip.Recipient) Like "*@*"))
ORDER BY Sum([Total_Bytes]/1024/1024) DESC;

************************************************************
VBScript :

strExcelPath = "z:\project\file.xls"

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
objExcel.Sheets.Add ,objExcel.Sheets(objExcel.Sheets.Count)
x = 1

Set oSheet1 = objExcel.ActiveWorkbook.Worksheets(1)
oSheet1.Name = "abc"
oSheet1.Cells(2,1).Value = "Recip_Domain"
oSheet1.Cells(2,2).Value = "Total MB"
oSheet1.Cells(2,3).Value = "Recip Counts"

Set conn = CreateObject("ADODB.Connection")
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=z:\Project\test.mdb"
conn.Open strConnect


set rs=createobject("adodb.recordset")
MySavedQuery ="Corp009eSenderToHomeEmail"
rs.open MySavedQuery, conn, 0, 4
intRow = 2

Do While not rs.EOF
Wscript.Echo RS(0)

intRow = intRow + 1
oSheet1.Cells(introw, 1) = RS(0)
oSheet1.Cells(introw, 2) = RS(1)
oSheet1.Cells(introw, 3) = RS(2)
rs.MoveNext
Loop
rs.Close
set rs = nothing
*********************************************************

My System SpecsSystem Spec
Old 09-18-2008   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: VBScript problem in running Stored Query


"Codeblack" <Codeblack@xxxxxx> wrote in message
news:1B0CA8FC-699F-42C7-8B13-20E0167BE2AE@xxxxxx
Quote:

>I am having strange problem. I have a saved query in MS Access which works
> absolutely fine without any problems. But when I try to call the stored
> query
> from VBScript I get the below error. In fact the database has records in
> it.
> Can anyone tell me what could be the problem. Any help will be greatly
> appreciated
>
> *******************************************
> Error
> Either BOF or EOF is True, or the current record has been deleted.
>
> *************************************************
> MS Access Query
>
> SELECT SenderToRecip.Sender, AllEmployees.DeptCode,
> AllEmployees.Department,
> AllEmployees.City, SenderToRecip.Recipient, Sum([Total_Bytes]/1024/1024)
> AS
> Total_MB, Sum(SenderToRecip.Recip_Counts) AS Recip_Counts FROM
> [Corp009d-Skip] INNER JOIN (SenderToRecip INNER JOIN
> AllEmployees ON SenderToRecip.Sender=AllEmployees.Email) ON
> ([Corp009d-Skip].recipient=SenderToRecip.Recipient) AND
> ([Corp009d-Skip].sender=SenderToRecip.Sender)
> WHERE
> (((InStr(Left(SenderToRecip.Recipient,InStr(SenderToRecip.Recipient,"@")-1),[LName]))>0))
> GROUP BY SenderToRecip.Sender, AllEmployees.DeptCode,
> AllEmployees.Department, AllEmployees.City, SenderToRecip.Recipient
> HAVING (((SenderToRecip.Recipient) Like "*@*"))
> ORDER BY Sum([Total_Bytes]/1024/1024) DESC;
>
> ************************************************************
> VBScript :
>
> strExcelPath = "z:\project\file.xls"
>
> Set objExcel = CreateObject("Excel.Application")
> objExcel.Visible = True
> objExcel.Workbooks.Add
> objExcel.Sheets.Add ,objExcel.Sheets(objExcel.Sheets.Count)
> x = 1
>
> Set oSheet1 = objExcel.ActiveWorkbook.Worksheets(1)
> oSheet1.Name = "abc"
> oSheet1.Cells(2,1).Value = "Recip_Domain"
> oSheet1.Cells(2,2).Value = "Total MB"
> oSheet1.Cells(2,3).Value = "Recip Counts"
>
> Set conn = CreateObject("ADODB.Connection")
> strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=z:\Project\test.mdb"
> conn.Open strConnect
>
>
> set rs=createobject("adodb.recordset")
> MySavedQuery ="Corp009eSenderToHomeEmail"
> rs.open MySavedQuery, conn, 0, 4
> intRow = 2
>
> Do While not rs.EOF
> Wscript.Echo RS(0)
>
> intRow = intRow + 1
> oSheet1.Cells(introw, 1) = RS(0)
> oSheet1.Cells(introw, 2) = RS(1)
> oSheet1.Cells(introw, 3) = RS(2)
> rs.MoveNext
> Loop
> rs.Close
> set rs = nothing
> *********************************************************
The error doesn't make sense to me, as nothing should happen if rs.EOF is
True (you don't say which line raised the error, but I assume it is not
rs.Close). I would suspect one of the parameters on the rs.Open statement.
Certainly, lockType = 4 (adLockBatchOptimistic) is not necessary. I would
use 1 or nothing. Maybe you need to specify an option (optional 5th
parameter), perhaps 4 = adCmdStoredProc. In fact, maybe that is what you
intended. Maybe it should be:

rs.Open MySavedQuery, conn, 0, 1, 4

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 09-18-2008   #3 (permalink)
Richard Mueller [MVP]


 
 

Re: VBScript problem in running Stored Query

I should have included a link to reference on Open method, which explains
options available for all parameters:

http://msdn.microsoft.com/en-us/library/ms675544.aspx

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 09-19-2008   #4 (permalink)
Codeblack


 
 

Re: VBScript problem in running Stored Query

Richard,

Thanks for looking into this. Tried the options which you mentioned but
gettig teh same error. I have simplified the code so that it will be easy to
read. The error is pointing at Wscript.Echo rs(0). Can you please tell me
what is wrong with the code. I tested thie query again in MS access and it
works absolutely fine. Any suggestions will be highly appreciated.

Set conn = CreateObject("ADODB.Connection")
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=z:\Project\test.mdb"
conn.Open strConnect
set rs=createobject("adodb.recordset")
MySavedQuery ="Corp009eSenderToHomeEmail"
rs.open MySavedQuery, conn, 0, 1, 4

Do While rs.EOF
Wscript.Echo rs(0) ' Error Here

rs.MoveNext
Loop





My System SpecsSystem Spec
Old 09-20-2008   #5 (permalink)
Codeblack


 
 

Re: VBScript problem in running Stored Query

Richard,

Any suggestions on this please.
My System SpecsSystem Spec
Old 09-22-2008   #6 (permalink)
Codeblack


 
 

Re: VBScript problem in running Stored Query

Does any one has any clue on why this problem is occurring.Can anyone please
help me on this.

Regards
Codeblack
My System SpecsSystem Spec
Old 09-24-2008   #7 (permalink)
Codeblack


 
 

Re: VBScript problem in running Stored Query

You are genius, the second suggestion (using %) worked for me. Thanks a lot
for your timelly help.

Regards
Codeblack
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
VBScript to Query WMI VB Script
execute mysql query using vbscript VB Script
SQL Query in VBScript VB Script
VBScript Problem with Access Query (Unspecified error) VB Script
Running WMI Query in without Powershell or VBS PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46