The problem is related to the usage of VFP COM server from Visual basic 6.0 (SP 6).
Code (relevant)
Private moVFPServer As f_vfpsvr.VFPServer
In the Sub:
Dim oRec As f_vfpsvr.VFPRecord
Set oRec = moVFPServer.NewRecord("LoanMstr")
With oRec
.SetField "ssn", sSSN
.SetField "awdyr", sAwardYear
.SetField "tran_date", Format(Now, "mm/dd/yyyy")
.Commit
End With
Method "NewRecord" from moVFPServer returns an object which represents a new, empty record in the VFP table "LoanMstr".
Code follows to populate properties/fields and save data.
All this works if VFP COM server is built using VFP 8.0 and does not work when built using VFP 9.0.
Specifically, VB application errors out at the line of code:
Set oRec = moVFPServer.NewRecord("StdMstr")
COM server throws exception: automation error -2147417851.
This is happening on the same machine.
VFP built COM objects can behave a little oddly at times, especially when it comes to trickling errors back up the stack.
But it seems very strange that this manifests only when built in VFP9. I believe there WERE some breaking changes in database stuff between 8 and 9 some possibly you've hit one of them?
Do you have an ERROR function in the VFP code? If not, try setting some error properties in that and interrogating them in VB when you get the error?
Ie, we have something like
FUNCTION ERROR(nError, cMethod, nLine)
THIS.cErrDesc = "Error Number: " + TRANSFORM(nError) + CRLF + "Message: " + MESSAGE() + CRLF + "Method: " + cMethod + CRLF + "Line #: " + TRANSFORM(nLine)
COMRETURNERROR(cMethod, THIS.cErrDesc)
ENDFUNC
Related
OK, so my database was originally designed in Access 2003. On one of the machines I am using a Access 2007 Runtime as the machine does not have Office of any flavor. I am trying to find a solution using the latest version of Access in Office 365. I cannot directly access either the live version running on either Access 2003 or Access 2007 Runtime. I cannot change the versions on the other machines as these are located in a prison and have no internet. This works without issue running in 2003, only the 2007 is the issue. As I am not there and only have 365, I need a solution that will work for all versions.
The functions being used are in separate modules and are not on the actual form. The form is set to have module as that is required to access the objects. The function is to add an session for an inmate to attend the library. This must be verified to make sure there is room at the time and day of week selected, as well as individual session limits.
The issue I am dealing with is the 2007 and 365 versions are unable to get the selected data from a list box (time as a string) and option group (DayofWeek as number) to complete a SQL query instead it inserts nothing and the SQL fails claiming there is an extra ) in my code. The SQL is then used to create a DAO recordset. This is part of a verification of data to ensure limits are not reached.
I have triple checked the string sent to CO_GetSessionDetail to ensure I do not have an extra ). It thinks it does as there is nothing on the right side of my = in the string. I checked the reference to the form and the unbound fields and they all match. It compiles no problem.
THERE IS NO ISSUE IN 2003 ...
The code is posted below.
Function CO_NewCallout() As Boolean
...
' Get Session ID --------------------------------- '
With Form_f_COs_IM
iSession = CO_GetSessionDetail( _
"SessionID", _
"(((t_CO_Sess.DayOfWeek) = " & .CO_Add_DayOfWeek & ") AND " & _
"((t_CO_Sess.tSession) = '" & .CO_Add_tSession & "'))" _
)
If iSession = 0 Then
GoTo CO_NewCallout_Exit
End If
End With
...
End Function
Function CO_GetSessionDetail(stfield As String, stwhere As String) As Variant
'On Error Resume Next
' Variable Declerations -------------------------- '
Dim db As Database
Dim rst As DAO.Recordset
Dim stSQL As String
' Set Variables ---------------------------------- '
Set db = CurrentDb
If stwhere <> "" Then
stwhere = "WHERE " & stwhere
End If
stSQL = _
"SELECT * " & _
"FROM t_CO_Sess " & stwhere
Set rst = db.OpenRecordset(stSQL, dbOpenDynaset)
' Get Session ID --------------------------------- '
With rst
If Not .EOF Then
CO_GetSessionDetail = .Fields(stfield)
Else
CO_GetSessionDetail = 0
End If
End With
' Close Recordset t_CO_Sess ---------------------- '
rst.Close
Set rst = Nothing
End Function
Access 2003 - I get the unique ID of the Session
Access 2007 and 365 - cannot complete function
Let me know if more code would help.
An Access application compiled using Office 365 will not be compatible with the Access 2007 runtime or Access 2003. You must compile on a version earlier or equal to the runtime you choose. Unfortunately, it is hard to get the Access 2003 runtime because it is not freely downloadable. The 2007 runtime is freely available (which probably explains why you chose to install the later version).
Your code looks OK, and I assume it compiles and all that. Despite the fact that your 2003 database should work with the Access 2007 runtime, the fact that it doesn't says to me that you have an incompatibility you need to resolve.
Your best bet: upgrade your app to 2007 or later, ensure it works in the new version, and install the matching runtime on your client's machines.
References:
General discussion of Access version compatibility:
Access 2016/2010 Compatibility, Access 2016
Article on getting the Access 2003 Runtime:
MS Access Runtime 2003
I have a desktop application written in VB.net that runs a macro in an access. Recently we upgraded from office 2010 to office 365. Now when i run this application i get this error :
Exception that comes up
Error Image
Could not load file or assembly 'Microsoft.Office.Interop.Acces.Dao,Version =15.0.0.0...' or one of its dependencies'
Below is the code that causes the exception:
If _accessApp Is Nothing Then
_accessApp = New Application
End If
Try
If JobFolderPath.Length <= 0 Or JobFolderPath Is Nothing Then
Exit Sub
End If
If _accessApp.CurrentDb() Is Nothing Then
_accessApp.OpenCurrentDatabase(JobFolderPath & "somedb.mdb", False)
_accessApp.Run("SomeProcess")
Else
_accessApp.Run("SomeProcess")
End If
_accessApp.Quit(AcQuitOption.acQuitSaveNone)
Catch ex As Exception
Finally
_accessApp = Nothing
End Try
I even included teh Interop.Access.Dao verion 15 dll in the references for the project. Not sure if this way of running macros is obsolete in access 16. If so, what is the correct way of doing this?
Thanks in advance.
The error also says "or one of its dependencies", install the interop from the link below.
https://www.nuget.org/packages/Microsoft.Office.Interop.Excel/15.0.4795.1000
Click on "Manual Download on the right ...
Not an answer to your question, but a macro can be run without Access references with late binding:
Dim accObj = GetObject(JobFolderPath & "somedb.mdb") ' opens the file if not already open
accObj.Application.Run("SomeProcess") ' the .Application part might not be needed
accObj.Application.Quit(2) ' AcQuitOption.acQuitSaveNone = 2
or command line switches (also not tested):
Process.Start(JobFolderPath & "somedb.mdb" "/x SomeProcess")
Finally i was able to fix it by installing 'microsoft office 16.0 access database engine'(32 bit version) and adding the required dlls as COM references instead of normal dll references.
I have a VB.net program that I wrote and have used hundreds of times. Whilst using Windows 7 I "upgraded" to Office 2010 and IIRC had to make a few small changes to get it to work. I have now (and again I put it in quotes as I fail to see the benefits of calling it an upgrade !) "upgraded" to Windows 10 but went back to Office 2007 as I much prefer it. I am also using Visual Studio Community 2015. All of that may or may not be of help !!!
So, I run the program and it fails with the following error :
An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in
KA_Newsletter.exe
Additional information: Word cannot open this document template.
(L:...\Customize Ribbon Example 2.dotm)
I have looked up the error and there is a Microsoft page ...
MS Support Bug
... that suggests this may be a Bug, it explains why it may be happening and gives a resolution but I program for fun, I'm not an expert in VB at all and it may as well be written in Russian for all it helps me !!!
I also have no idea why Word should be trying to open that Example Template either, I copy a Template of my own to create a new Word document, this is pretty basic stuff !!! This is the relevant code, any help would be very much appreciated ...
Dim myNewsLetter As String
.
.
.
If File.Exists(myNewsLetter) Then
'do nothing
Else
myTemplate = myTempFolder & "KA_Newsletter.doc"
File.Copy(myTemplate, myNewsLetter)
Create_Blank_Newsletter()
End If
.
.
.
Private Sub Create_Blank_Newsletter()
myMSWord = New Word.Application
myMSDoc = myMSWord.Documents.Open(myNewsLetter) << <Error occurs on this line
myMSWord.WindowState= Word.WdWindowState.wdWindowStateNormal
myMSWord.Visible= False
UPDATE :
Olaf, I updated the code as follows ...
myMSWord = New Word.Application
Dim inval As Object
'Marshal the object before passing it to the method.
inval = New System.Runtime.InteropServices.DispatchWrapper(myNewsLetter)
myMSDoc = myMSWord.Documents.Open(inval)
'myMSDoc = myMSWord.Documents.Open(myNewsLetter)
... but I am getting a similar error on the Open statement ...
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in KA_Newsletter.exe
Additional information: Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))
Any ideas ?
The MS page says you should try something like
Dim inval As Object
'Marshal the object before passing it to the method.
inVal = New System.Runtime.InteropServices.DispatchWrapper(myNewsLetter)
myMSDoc = myMSWord.Documents.Open(inval)
I have a VB.NET project targeting framework 3.5 that references a dynamic DLL of compiled enums generated from a database. My project compiles and runs in Visual Studio 2012. I am beginning to upgrade my solutions to Visual Studio 2015 and ran in to a bunch of errors when I tried doing this project.
The two errors I get for just about every enum are
Operator '=' is not defined for types MyEnumType and MyEnumType
Field MyEnumType.Field has an invalid constant value
Viewing the definition of the enum meta data (which I can do in 2015 but not 2012) I see it being defined as
Enum EnumName as Object
Field1
Field2
End Enum
As you can see its appending As Object which I've never seen before. But that explains the operator = error because if it's an object than you would have to define an overloaded Equals operator.
I'm just seeing if anyone has any insight or know of anything in 2015 that would be causing this issue. I tried creating a new project an importing the .DLLs just to see if they worked at all in VS 2015. They work when referenced in C# but not in VB.NET. The .DLLs were written and compiled in VB.NET. S
For the time being I can still use 2012, but would like to upgrade to 2015 in the future and not have to rewrite a bunch of things.
EDIT:
Here is the (simplified) code that is being used to create the enum .DLL. An xml is being read with the Enum name and sql query used to generate the enum.
Dim myEnumBuilder As Emit.EnumBuilder
Dim myAppDomain as AppDomain
Dim myModuleBuilder As ModuleBuilder
Dim myAssemblyName As New AssemblyName()
myAssemblyName.Name = EnumDll.Name
' Create a dynamic assembly.
myAssemblyBuilder = myAppDomain.DefineDynamicAssembly(myAssemblyName, AssemblyBuilderAccess.Save, msOutputDirectoryPath)
' Create a dynamic module.
myModuleBuilder = myAssemblyBuilder.DefineDynamicModule("Library." & EnumDll.Name, EnumDll.Name & ".dll")
' Creating a dynamic Enum.
myEnumBuilder = myModuleBuilder.DefineEnum(EnumDll.Name & "." & EnumName, TypeAttributes.Public, GetType(Int32))
Dim myFieldBuilder As FieldBuilder = myEnumBuilder.DefineLiteral(StrEnum, CInt(oReader(0)))
myEnumBuilder.CreateType()
myAssemblyBuilder.Save(EnumDll.Name & ".dll") 'save the dll
I have a problem trying to access data pulled as an array from a VB.NET DLL.
The DLL is registered correctly and working on the web server which is serving the asp classic pages.
I have tested the dll using a vb6 program and it retrieved the data that I expect.
Here is the code that I used for that.
Dim commItems
commItems = c.GetCommTypes
For i = LBound(commItems) To UBound(commItems)
Me.Label2.Caption = "Item: " & commItems(i).CommTypeID & " - " & commItems(i).CommTypeName
DoEvents
Sleep (1000)
Next
The error message I get is as follows, when trying to do the same thing is asp clasic
Microsoft VBScript runtime error '800a000d'
Type mismatch
/commtype.asp, line 13
Here is my asp code
Dim Core
Set Core = Server.Createobject("Advantage.Dealer.Email.CoreClassLibrary.CoreClass")
dim commItems
commItems = Core.GetCommTypes
For i = LBound(commItems) to UBound(commItems)
Response.Write commItems(i).CommTypeID
Next
I am not sure what I'm doing wrong but if i run this code
Dim Core
Set Core = Server.Createobject("Advantage.Dealer.Email.CoreClassLibrary.CoreClass")
dim commItems
commItems = Core.GetCommTypes
For i = LBound(commItems) to UBound(commItems)
Response.Write i
Next
I get
0123
So something is working, but not how I want it to.
Please be aware that it should return 4 rows of data
I would review the COM interface for the type returned in the array by the Core.GetCommTypes() method.
<InsiderKnowledge>
The Advantage.Dealer.Email.ModelClassLibrary.CommType class does not appear to have a COM interface declared.
This does not tally with your VB6 client successfully being able to consume its properties. Have you modified your assembly/assemblies between executing your VB6 and VB Script tests against them?
</InsiderKnowledge>
Ok so after a few more hours searching I found the solution I was looking for.
I found the answer here
http://bytes.com/topic/asp-classic/answers/167046-type-mismatch-error-when-accessing-array
Right at the bottom of the post.
Basically I was passing an array of my class type, and what I should have been doing is returning an array of System.Object type. I made some changes to my .net DLL so that rather than returning an array of the CommType Class it was returning an Array of System.Object