473,734 Members | 2,806 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DISP_E_BADVARTY PE error at runtime

I'm getting this error from the JIT compiler at runtime, but only on my boss'
machine, not my development machine. I believe the error is generated from a
call to an Excel object, but I can't tell why or what specific action on the
object is causing it.

We both are running version 2.0 of the .net framework with Office 2003
installed, though I am running XP and she has Win2000. Also, I do not get
this error when running another sub in the same application that also calls
Excel and is otherwise very similar, sharing much of the same code.

This is the offending code (please take it easy, this is my first attempt at
..net and is a port from a VBA app at that):

Module QuickViewer
Public objChosenOne(4) As Object
Public strCode As String
Public strWS As String

Sub QuickView()
Dim e As New Microsoft.Offic e.Interop.Excel .Application
Dim rngCell As Microsoft.Offic e.Interop.Excel .Range
Dim bkQuery As Microsoft.Offic e.Interop.Excel .Workbook
Dim bkLookup As Microsoft.Offic e.Interop.Excel .Workbook
Dim shQuery As Microsoft.Offic e.Interop.Excel .Worksheet
Dim intCount As Integer
Dim intSplit(1) As Integer
Dim strTable As String
Dim intColCount As Integer

'query the appropriate database and return to a new workbook
strTable = objChosenOne(2) .ToString & "-" & objChosenOne(1) .ToString

bkQuery = e.Workbooks.Add

'delete all worksheets except the first
e.DisplayAlerts = False
Do
If bkQuery.Sheets( bkQuery.Sheets. Count).Index 1 Then
bkQuery.Sheets( bkQuery.Sheets. Count).Delete()
Loop Until bkQuery.Sheets. Count = 1
e.DisplayAlerts = True

shQuery = CType(bkQuery.A ctiveSheet,
Microsoft.Offic e.Interop.Excel .Worksheet)

With shQuery.QueryTa bles.Add(Connec tion:="ODBC;DSN =MS Access
Database;DBQ=" & strPath & "\" & objChosenOne(1) & ".mdb;DefaultDi r=" &
strPath & ";DriverId=25;F IL=MS Access;MaxBuffe rSize=2048;Page Timeout=5;",
Destination:=sh Query.Range("$A $1"))
.CommandText = "SELECT `" & strTable & "`.`Record Number`, `" &
strTable & "`.`Workshe et Code`, `" & strTable & "`.Line, `" & strTable &
"`.Column, `" & strTable & "`.Value" & vbCrLf & "FROM `" & strPath & "\" &
objChosenOne(1) & "`.`" & strTable & "` `" & strTable & "`" & vbCrLf & "WHERE
(`" & strTable & "`.`Record Number`=" & objChosenOne(0) & ")"
.Name = "Query from MS Access Database_1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFo rmulas = False
.PreserveFormat ting = True
.RefreshOnFileO pen = False
.BackgroundQuer y = True
.RefreshStyle =
Microsoft.Offic e.Interop.Excel .XlCellInsertio nMode.xlInsertD eleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWi dth = True
.RefreshPeriod = 0
.PreserveColumn Info = True
.Refresh(Backgr oundQuery:=Fals e)
End With

shQuery.Columns (2).Insert()
shQuery.Range(" B2",
shQuery.Range(" A2").End(Micros oft.Office.Inte rop.Excel.XlDir ection.xlDown). Offset(0, 1)).Formula = "=C2&D2&E2"

'add worksheet descriptions
bkLookup = e.Workbooks.Ope n(strPath & "\HCRIS Codes.xls")
shQuery.Columns (2).Insert()
With shQuery.Range(" B2:B" & shQuery.Cells(s hQuery.Rows.Cou nt,
1).End(Microsof t.Office.Intero p.Excel.XlDirec tion.xlUp).Row)
.NumberFormat = "General"
.FormulaR1C1 = "=IF(ISERROR(VL OOKUP(RC[2],'" & bkLookup.Name &
"'!HCRISCodes,2 ,0)),"""",VLOOK UP(RC[2],'" & bkLookup.Name &
"'!HCRISCodes,2 ,0))"
.Copy()

..PasteSpecial( Microsoft.Offic e.Interop.Excel .XlPasteType.xl PasteValues)
End With

'sort the workbook
shQuery.Range(" A1:G" & shQuery.Cells(s hQuery.Rows.Cou nt,
1).End(Microsof t.Office.Intero p.Excel.XlDirec tion.xlUp).Row) .Sort(Key1:=shQ uery.Range("D1" ),
Order1:=Microso ft.Office.Inter op.Excel.XlSort Order.xlAscendi ng,
Key2:=shQuery.R ange("F1"),
Order2:=Microso ft.Office.Inter op.Excel.XlSort Order.xlAscendi ng,
Key3:=shQuery.R ange("E1"),
Order3:=Microso ft.Office.Inter op.Excel.XlSort Order.xlAscendi ng,
Header:=Microso ft.Office.Inter op.Excel.XlYesN oGuess.xlYes,
Orientation:=Mi crosoft.Office. Interop.Excel.X lSortOrientatio n.xlSortColumns )

'convert query result from text to general format
For Each rngCell In shQuery.Range(" G1:G" &
shQuery.Cells(s hQuery.Rows.Cou nt,
1).End(Microsof t.Office.Intero p.Excel.XlDirec tion.xlUp).Row)
rngCell.Value = rngCell.Value
Next

'split into individual worksheets

For Each rngCell In shQuery.Range(" D2:D" &
shQuery.Cells(s hQuery.Rows.Cou nt,
2).End(Microsof t.Office.Intero p.Excel.XlDirec tion.xlUp).Row + 1)
If rngCell.Value <rngCell.Offset (-1, 0).Value Then
If rngCell.Value = strCode Then
intSplit(0) = rngCell.Row
End If
If rngCell.Offset(-1, 0).Value = strCode Then
intSplit(1) = rngCell.Offset(-1, 0).Row
End If
End If
Next

If intSplit(0) = 0 Then 'worksheet not found
e.DisplayAlerts = False
e.Quit()
frmQuickView.ss Out.ActiveSheet .Range("C2").Va lue = "Worksheet "
& strWS & " does not exist for this cost report"
frmQuickView.Br ingToFront()
Exit Sub
Else
End If

bkQuery.Workshe ets.Add(After:= bkQuery.Sheets( 1))
shQuery = CType(bkQuery.S heets(1),
Microsoft.Offic e.Interop.Excel .Worksheet)
shQuery.Activat e()
shQuery.Range(s hQuery.Cells(in tSplit(0), 4),
shQuery.Cells(i ntSplit(1), 4)).Copy()

shQuery = CType(bkQuery.S heets(2),
Microsoft.Offic e.Interop.Excel .Worksheet)
shQuery.Activat e()

shQuery.Range(" A2").PasteSpeci al(Microsoft.Of fice.Interop.Ex cel.XlPasteType .xlPasteValues)

shQuery = CType(bkQuery.S heets(1),
Microsoft.Offic e.Interop.Excel .Worksheet)
shQuery.Activat e()
shQuery.Range(s hQuery.Cells(in tSplit(0), 2),
shQuery.Cells(i ntSplit(1), 2)).Copy()

shQuery = CType(bkQuery.S heets(2),
Microsoft.Offic e.Interop.Excel .Worksheet)
shQuery.Activat e()

shQuery.Range(" B2").PasteSpeci al(Microsoft.Of fice.Interop.Ex cel.XlPasteType .xlPasteValues)

shQuery = CType(bkQuery.S heets(1),
Microsoft.Offic e.Interop.Excel .Worksheet)
shQuery.Activat e()
shQuery.Range(s hQuery.Cells(in tSplit(0), 5),
shQuery.Cells(i ntSplit(1), 6)).Copy()

shQuery = CType(bkQuery.S heets(2),
Microsoft.Offic e.Interop.Excel .Worksheet)
shQuery.Activat e()

shQuery.Range(" C2").PasteSpeci al(Microsoft.Of fice.Interop.Ex cel.XlPasteType .xlPasteValues)

'break the "column" column into actual columns

For Each rngCell In shQuery.Range(" D2:D" &
shQuery.Cells(s hQuery.Rows.Cou nt,
4).End(Microsof t.Office.Intero p.Excel.XlDirec tion.xlUp).Row)
If rngCell.Value <rngCell.Offset (-1, 0).Value Then
Try
shQuery.Cells(1 , intColCount + 5).Value = "'" &
CStr(Format(CIn t(rngCell.Value ), "0000"))
Catch
End Try
intColCount = intColCount + 1
End If
Next
shQuery.Columns (4).Delete()

'sort by line number and eliminate duplicate lines
shQuery.Range(" A2:C" & shQuery.Cells(s hQuery.Rows.Cou nt,
1).End(Microsof t.Office.Intero p.Excel.XlDirec tion.xlUp).Row) .Sort(Key1:=shQ uery.Range("C2" ),
Order1:=Microso ft.Office.Inter op.Excel.XlSort Order.xlAscendi ng,
Header:=Microso ft.Office.Inter op.Excel.XlYesN oGuess.xlNo,
Orientation:=Mi crosoft.Office. Interop.Excel.X lSortOrientatio n.xlSortColumns )
For intCount = CLng(shQuery.Ce lls(shQuery.Row s.Count,
1).End(Microsof t.Office.Intero p.Excel.XlDirec tion.xlUp).Row) To 3 Step -1
If shQuery.Cells(i ntCount, 3).Value = shQuery.Cells(i ntCount -
1, 3).Value Then
shQuery.Rows(in tCount).Delete( )
End If
Next

'lookup values
shQuery = CType(bkQuery.S heets(1),
Microsoft.Offic e.Interop.Excel .Worksheet)
shQuery.Activat e()
bkQuery.Names.A dd(Name:="LU", RefersTo:=shQue ry.Range("$C$2: $G$" &
shQuery.Cells(s hQuery.Rows.Cou nt,
3).End(Microsof t.Office.Intero p.Excel.XlDirec tion.xlUp).Row) )

shQuery = CType(bkQuery.S heets(2),
Microsoft.Offic e.Interop.Excel .Worksheet)
shQuery.Activat e()
With shQuery.Range(" D2",
shQuery.Cells(s hQuery.Cells(sh Query.Rows.Coun t,
3).End(Microsof t.Office.Intero p.Excel.XlDirec tion.xlUp).Row, shQuery.Cells(1 ,
shQuery.Columns .Count).End(Mic rosoft.Office.I nterop.Excel.Xl Direction.xlToL eft).Column))
.Formula =
"=IF(ISERROR(VL OOKUP($A2&$C2&D $1,LU,5,0)),""" ",VLOOKUP($A2&$ C2&D$1,LU,5,0)) "
.Copy()

..PasteSpecial( Microsoft.Offic e.Interop.Excel .XlPasteType.xl PasteValues)
End With

'add headings and formatting

shQuery.Range(" A1:C1").Value = "Worksheet Code"
shQuery.Range(" A1:C1").Value = "Worksheet"
shQuery.Range(" A1:C1").Value = "Line"
shQuery.Rows(1) .Font.Bold = True
shQuery.Cells.C olumns.AutoFit( )
shQuery.Columns (1).Hidden = True
shQuery.Range(" D2").Select()
e.ActiveWindow. FreezePanes = True

For Each rngCell In shQuery.Range(" D2",
shQuery.Cells(s hQuery.Cells(sh Query.Rows.Coun t,
3).End(Microsof t.Office.Intero p.Excel.XlDirec tion.xlUp).Row, shQuery.Cells(1 ,
shQuery.Columns .Count).End(Mic rosoft.Office.I nterop.Excel.Xl Direction.xlToL eft).Column))
If IsNumeric(rngCe ll.Value) Then
If rngCell.Value - Int(rngCell.Val ue) <0 Then
rngCell.NumberF ormat = "_(* #,##0.000000_); _(*
(#,##0.000000); _(* ""-""??_);_(@_ )"
Else
rngCell.NumberF ormat = "_(* #,##0_);_(* (#,##0);_(*
""-""??_);_(@_ )"
End If
End If
Next

e.DisplayAlerts = False
bkQuery.Sheets( 1).Delete()
bkQuery.ActiveS heet.Cells.Copy ()

With frmQuickView.ss Out.ActiveSheet
.Range("A1").Pa ste()
.Cells.Interior .ColorIndex = 36
.Range("C2").Se lect()
.Cells.AutoFit( )
End With

'CLEANUP CODE
'brute force method of releasing the COM object may generate error
when object is set to nothing twice
Try
If Not bkQuery Is Nothing Then bkQuery.Close(F alse)
Catch
End Try
Try
If Not bkLookup Is Nothing Then bkLookup.Close( False)
Catch
End Try
Try
If Not e Is Nothing Then e.Quit()
Catch
End Try

Try
rngCell = Nothing
Catch
End Try
Try
shQuery = Nothing
Catch
End Try
Try
bkQuery = Nothing
Catch
End Try
Try
bkLookup = Nothing
Catch
End Try
Try
e = Nothing
Catch
End Try

If Not rngCell Is Nothing Then
Do
If
(System.Runtime .InteropService s.Marshal.Relea seComObject(rng Cell) = 0) Then
Exit Do
Loop
End If
If Not shQuery Is Nothing Then
Do
If
(System.Runtime .InteropService s.Marshal.Relea seComObject(shQ uery) = 0) Then
Exit Do
Loop
End If
If Not bkQuery Is Nothing Then
Do
If
(System.Runtime .InteropService s.Marshal.Relea seComObject(bkQ uery) = 0) Then
Exit Do
Loop
End If
If Not bkLookup Is Nothing Then
Do
If
(System.Runtime .InteropService s.Marshal.Relea seComObject(bkL ookup) = 0) Then
Exit Do
Loop
End If
If Not e Is Nothing Then
Do
If
(System.Runtime .InteropService s.Marshal.Relea seComObject(e) = 0) Then Exit Do
Loop
End If

rngCell = Nothing
shQuery = Nothing
bkQuery = Nothing
bkLookup = Nothing
e = Nothing

System.GC.Colle ct()

End Sub

End Module

Thanks!
Aug 9 '06 #1
0 3239

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2668
by: Don Stevic | last post by:
I am running VS2005 and using VSTO for Word. I keep getting this error saying that there is no source code available for this location when I try and run this application. I am going to try and reinstall Office 2003 and see if that fixes this, but it is talking about the mscorlib.dll and that isn’t Office.
2
2588
by: Maximus | last post by:
Hi Everyone, I was using Inprocess session objects, but incase of aspnet process crashes the session objects were lost as a result I decided to shift to out of porocess session objects. For this i had to serialize the objects. While doing that I made the classes serializable whose objects I store in sessions. However, when I run the application I get the following error.
2
6938
by: Kevin R. | last post by:
I have been ignoring this problem for a few weeks now, but it's becoming a bit annoying not to mention unproductive. Here it goes: I compile my project with no errors. Then after I debug/run it, I get the runtime error noted at the end of this message. If I re-compile (without any changes) and re-run, then my project will run OK. This behavior is very consistent. Another words, the only way I can run an ASP.NET application is if I...
16
2957
by: | last post by:
Hi all, I have a website running on beta 2.0 on server 2003 web sp1 and I keep getting the following error:- Error In: http://www.mywebsite.org/WebResource.axd?d=5WvLfhnJp5Lc8WhQSD4gdA2&t=632614619884218750 -------------------------------------------------------------------------------- System.Security.Cryptography.CryptographicException: Padding is invalid and cannot be removed. at...
0
1632
by: aartinawani | last post by:
Hi I have an asp.net application running under Windows 2003 Server, IIS 6, for 2 years. Today, suddenly, the site went down at 3:38 pm and the application raised an error entitled "Server too busy". Searching the event logs I found an entry for: Event ID: 0 Source:.NET Runtime
2
3744
by: Lonewolf | last post by:
hi all, I realize the example on MSDN for IPCChannel has compile error in VS2005 pro. Either I'm missing something or there's something seriously wrong with MSDN on that section. I reproduce the MSDN code sample for IPCchannel for server side in c# below. please help me see what I'm missing here. using System; using System.Runtime.Remoting.Channels.Ipc;
669
26076
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990. http://www.ccs.neu.edu/home/cobbe/pl-seminar-jr/notes/2003-sep-26/expressive-slides.pdf
7
8452
by: Norman Diamond | last post by:
A project depends on VC runtime from Visual Studio 2005 SP1, and DotNet Framework 2. Options are set in the setup project properties, so if these two dependencies are not already installed then this installer will install them. But what about the situation where VC runtime has already been installed? In fact it's been installed twice. Although the project was built on a Windows XP system with Visual Studio 2005 SP1 and the results were...
1
4085
by: BL3WC | last post by:
Hi, I'd created a MDE under Access 2003. It is now under testing stage. Some of the users will use Access 2003 runtime and some will use Access 2007 runtime to run this MDE. I installed the Access 2007 runtime on a test machine and place the MDE in the Desktop for user's initial testing. I did not create a trust area for this MDE in the test machine as well as in my development machine. When I tested the MDE using /runtime switch in my...
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.