I wrote an MS Access app in Office 2007 and am now trying to modify it to run on Office 2010 64 bit version. I get the following error:
The expression On Open you entered as the event property setting produced the following error: Private Enum and user defined types cannot be used as parameters or return types for public procedures, public data members, or fields of public user defined types.
The error occurs if I try to open a form that has no code in its Open event, so I'm not sure where to start looking to make changes.
Thanks!
These sort of strange errors can arise if there are broken references. In the database open the VB window, on the menu choose Tools -> References. In the dialog box the references required will be at the top, check to see if any have "MISSING" prefixing the name.
Related
I would like to know if it is possible in a Saved Query on MS Access to use WHERE clause getting value from a Form independent of MS Access installed language?
In a MS SQL QUERY WHERE clause that should be equal to a text in a form, I wrote it like this
= Form!Form_name!text_name
This work fine if all user have MS English version installed, however, this is not true in my case, as some users have a Portuguese version. In their version, the right way to call the same syntax should be:
= Formulários!Form_name!text_name
So, the problem is that Access does not recognize this considering language version. Due to this, if a user with Portuguese version try to run the query, it will pop up an insert box.
I've look throughout many sources but none could help me to solve this.
Thank you all in advance!
I can't test this as I don't have a portuguese version of Access but I avoid calls to form parameters because they are brittle. For instance the form has to be open or the query fails in wierd ways. If I must use a form's parameter I wrap the parameter in a public function (usually in that forms code behind). A public function usually gets picked up by intellisense even in the designer but a public variable does not.
My style is to synthesize a property with a private global scope variable and public get and set functions. Then in the designer you can call: get-myforms-property instead of Form!Form_name!text_name. When the form opens and closes I usually call set-myforms-property and set it to be equal to the actual form property.
In this way you also get the advantages of wrapping. For instance you can choose what value to return when the form is closed rather than just having the query fail.
This question is a stumper, for experts only.
We are using Visual Studio 6 to develop a complex COM Add-In for Access. When compiled, the Add-In works fine. But, when we use Ctrl-F5 to put the VB6 IDE in debug mode, Access throws a
Run-time error 13: Type mismatch
error when it tries to assign the Access Application.COMAddIns("AddInName").Object reference to an early-bound VBA variable of a type exposed in the AddInName type library.
Further information:
The Access application uses objects created by calls to the Add-In
The Add-In DLL also serves as a type library that is included in Access VBA References
The type Access requests from the Add-In is defined in the AddInName type library
In Access VBA, the failing code looks like this:
Public Function GetAddInRef As AddInName.SomeClass
Dim objSomeClass As AddInName.SomeClass
' .Object is set to a SomeClass instance in IDTExtensibility2_OnConnection
Set objSomeClass = Application.COMAddIns("AddInName").Object ' => Error 13!
Set GetAddInRef = objSomeClass
End Function
If you change the type of objSomeClass to Object, the assignment works. If you set a break on the offending line, you can do things like this in the Immediate window:
? TypeName(objSomeClass)
AddInName.SomeClass
? TypeOf objSomeClass Is AddInName.SomeClass
False
So it is saying that the class name of objSomeClass is "AddInName.SomeClass", but it is not of type AddInName.SomeClass. Madness!
Further, if you put in code that exposes the CLSID for the Access-side reference and the Add-In originated object, they both return the same GUID! So why does VBA complain that the types are different?
Does anyone have any insight into what is happening here? I would be very grateful for any help.
I'm guessing (I am no expert) it's because AddInName.SomeClass is not an object, it is of type AddinName.SomeClass. Drop the .Object off of Application.COMAddIns("AddInName").Object and I think it will work just fine. If you need it as an object for somewhere else in your code, then change your AddInName.SomeClass types to Object and leave the .Object on Application.COMAddIns("AddInName").Object and it should work.
So a colleague of mine stumbled upon the answer: Set Access and VB6 permissions to administrator! I tried it, and VoilĂ , debugging works.
For each of the following executable files, Right-click, Properties, Configuration, then check Run this program as an administrator:
Office path:
MSACCESS.EXE (or EXCEL.EXE or WINWORD.EXE ...)
C:\Program Files (x86)\Microsoft Visual Studio\VB98\
VB6.EXE
LINK.EXE
Notes:
It probably helps to develop VB6 apps using an administrative login, too.
This makes sense, because VB6 had its start in the Windows 95 era, when users were pretty much the king of their OS instance.
Caveat: this may not be a perfect solution for very complex Access forms with lots of DLL interaction, but it is much better than nothing!
I am using VB.net in creating this application. My idea is when the main form loaded, there is another form with textboxes for the user to initialize connection to the sql server, and use that textbox value in calling the database for query.
Now, my problem is then main form closes the value in the textbox will be erased, and i have to type it again. When connecting for an SQL Server over the LAN, does it have the same process?
You should not be referencing controls' values for logical uses like that; instead use the value in the control to populate a more persistent program entity, such as a settings object.
In your particular case, with VB.net (and presumably WinForms), showing connection form with ShowDialog() allows the form to persist after it has been closed. You can add a public property to the form to expose the user-entered value to the code that called it, and DialogResult of OK when the user indicates the value is accepted (usually through a button click).
I'd provide a code example, but I've been deep in C# for more than a few months now and my VB.Net is getting rusty.
MS Access 2007 (and perhaps later versions) appears to have a bug that causes a hard crash when a report open is canceled in the On No Data event and the On Close event contains a call to a public function. This does not appear to be an issue with MS Access 2003 or earlier.
Steps to reproduce:
Create a new report in MS Access 2007 (this is not an issue in MS Access 2003 and prior)
Set the recordsource (it can be anything, but it must be a bound report)
Set event On No Data to [Event Procedure]
In the code module for the report, enter:
Private Sub Report_NoData(Cancel As Integer)`
Cancel = True
End Sub
Set event On Close to =Foo()
In a standard code module, add the following code:
Public Function Foo()
End Function
Open the report using a filter that excludes all data (in order to raise the No Data event)
Results:
Access immediately suffers a hard crash with the "Access has stopped working..." error message
Two questions:
Is there a workaround?
Is this a known issue? (known to Microsoft or the greater MS Access community)
Workaround
There are a couple of workarounds:
Replace the function call in the report's On Close property with "[Event Procedure]" and then call the function from within the report's Private Sub Report_Close() in VBA.
- OR -
Move the function call from the report's On Close property to its On Unload property. (Note: the On Unload report property was introduced with MS Access 2007)
I am getting error message in ms access 2003. In access the 2 dll references are already added.
GeneralLink
CommonLink
I have to remove "CommonLink" reference from access project. I created one project "MyCommonLink" which is same as "CommonLink". When I remove "CommonLink" reference & adding new "MyCommonLink" reference while compiling it gives me "User - defined type not defined" error. Without any line of code highlighting.
Also I was checked that both project's code are same & dll files are registered.
Can anybody help me for how do I find for which object I am getting this error or which object was remain unreferenced?
could someone help me please? Thank you so much in advance.
Do a search in the code pages for "GeneralLink". There must be an object being declared somewhere that is fully qualified starting with GeneralLink (e.g. Dim x As GeneralLink.SomeObject). Or maybe there is a Public Enum in GeneralLink that is fully qualified somewhere (e.g. If x = GeneralLink.MyEnum.Item1 Then)