![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 > ********************************************************* 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| | #5 (permalink) |
| | Re: VBScript problem in running Stored Query Richard, Any suggestions on this please. |
My System Specs![]() |
| | #6 (permalink) |
| | 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 Specs![]() |
| | #7 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||