VBA Access User-Defined Type not Defined when Running my AutoExec Macro - ms-access

I am trying to test out my code that I have written, and when I go to run my AutoExec macro, I get the error
"User-defined type not Defined"
on the following line of code:
Public Sub WFR_Style(xlBook As Excel.Workbook)
I have the following references set up under my Tools->References:
Microsoft Access 16.0 Object Library
OLE Automation
Microsoft ActiveX Data Objects 6.1 Library
Microsoft Outlook 16.0 Object Library
Microsoft Office 16.0 Access database engine object library
Visual Basic for Applications
Am I missing any?

Related

ms access compile error: user-defined type not defined

i am trying to add this to my code :
Dim myRS1 As DAO.Recordset
yet it gives me this error:
Compile error: user-defined type not defined
I have gone through these links:
compile error: user-defined type not defined
Compiler Error: User-defined types not defined
What is "Compile error User-defined type not defined"?
w7 -> VB6 error "User-defined type not defined"
http://www.tek-tips.com/viewthread.cfm?qid=1731794
Yet to no avail.
I have tried adding the Microsoft Access 3.6 library yet then it says Error in loading DLL
I don't understand, my previous projects use the exact same code yet they work completely fine.
I guess we are taking about Access 2003 here.
In the Visual Basic windows, menu 'Tools > References' having ticked & selected 'Microsoft DAO 3.6 Object Library', it should show the location of the DLL at the bottom of the form. It will be something like:
C:\Program Files\Common Files\Microsoft Shared\DAO\DAO360.DLL
Check that DLL, and associated files exist. Compare the folders contents with another working PC, and copy across files as necessary. (Always take backup of original state.) The error 'Error in loading DLL' may indicate a corrupted DLL.
Also check the 'Object Browser', in the Visual Basic windows, menu 'View > Object Browser'. You should able to select the 'DAO' library in the Top Combo, and then browse it's Classes & Members.

How to programmatically convert Access 1997 .mdb to Access 2007 .accdb

I'm in the starting process of building an application that walks through a folder structure, starting at a given root path, and converts all found Access 1997 .mdb files into the newer Access 2007/2010 .accdb format. However, I'm running into some troubles when doing to actual file conversion.
I'm using Microsoft's Access Interop API (https://msdn.microsoft.com/en-us/library/office/ff193465.aspx) to handle the conversion, so this has to be written in VBScript. Script is below:
Dim app
Set app = CreateObject("Access.Application")
app.ConvertAccessProject "C:\Users\[User]\Access Conversion Utility\sample.mdb", "C:\Users\[User]\Access Conversion Utility\converted.accdb", acFileFormatAccess12
When run, I get the error "The project cannot be converted into this format. The project can only be converted to Access 2000 or newer format." Yet, this same error message shows up regardless of the file parameter enum value, be it 'acFileFormatAccess97' or 'acFileFormatAccess2000'. Does anyone know the details of this error and what a possible solution could be? I've tried changing the extension of the second parameter, thinking that was part of the issue, but this made no changes to the error message.
The sample file I'm using is able to be opened in Access just fine, it's just the conversion itself that fails.
By all means, if anyone has a better idea or approach to do the conversion programatically, I would love to hear it, but this is the only one I was able to find. The plan is to run this script from a GUI application written in C#, but also allow for the application to be run via the command line as well.
I'm using Microsoft's Access Interop API ... so this has to be written in VBScript.
Nonsense. I just tried this in C# (Visual Studio 2010) and it worked fine for me with Access 2010:
// COM reference required for project
// Microsoft Access 14.0 Object Library
var app = new Microsoft.Office.Interop.Access.Application();
app.ConvertAccessProject(
#"C:\Users\Public\test\a97test.mdb",
#"C:\Users\Public\test\a2007converted.accdb",
Microsoft.Office.Interop.Access.AcFileFormat.acFileFormatAccess2007);
app.Quit();
Note that this will almost certainly not work with Access 2013 and later, but neither would a VBScript implementation of COM Interop for those versions of Access since they absolutely refuse to open Access_97 (and earlier) databases.
Problem is twofold.
First, Access 2007 and later won't read older formats than the JET 4 format of Access 2000.
Second, the constant for the 2007 format is acFileFormatAccess2007, not acFileFormatAccess12, it's the numeric value of the constant that is 12.
On this point, the documentation is wrong:
AcFileFormat Enumeration (Access)
So you will have to obtain an older version of Access for the first conversion to JET 4, then another step to convert to 2007 format.
Edit:
Or, of course, do as Gord shows.
Plain VBScript does not know about the ac* constants. So define them properly.

Searching for referenced file Excel.exe in VBA script after converting to Office 2013

I have an Access application that I share with other users. We share the database on a Sharepoint site and each check it out / download it for edits, then put it back in Sharepoint and check it back in. We do it this way because response time if we all share the same copy on a server is unacceptable, and we only need one person to have acces at any one time. That's not my problem right now.
Last week, my old PC died and I replaced it with a new one. The old PC is Windows7, 32 bit, with Office 2010. The new PC is also Windows7, but 64 bit and with Office 2013. As far as I know, I did not change the database format to a new version of Access or make any other changes. The data base still works fine on my new PC.
The VBA script integrates the data base with Excel workbooks and exports data to Excel. One reference I have selected is Microsoft Excel 15.0 Object Library - the same reference I've always used. Now, when I load the database back to the server and other users downloads it, they can open the data base but get an error that says "Searching for reference file Excel.exe", followed by “Undefined function ‘Format’ in expression”.
The other users' PCs are configured the way my old one was, and they were able to use the database with no problems before I converted to Office 13 and saved my copy back to the server.
So my questions are - what is causing this, and more importantly, what can I do to fix it?
"... reference I have selected is Microsoft Excel 15.0 Object Library ..."
That Microsoft Excel 15.0 Object Library is the version for Office 2013. With Office 2010, the version is Microsoft Excel 14.0 Object Library.
The reference was originally 14.0 when you developed and used the db in Access 2010. When opened in Access 2013, Access adjusted the reference to its available version (15.0). Unfortunately, when you try to use the db again in Access 2010, Microsoft Excel 15.0 Object Library is meaningless to that Access version, so it doesn't know to use Microsoft Excel 14.0 Object Library instead.
The fix is to remove that reference and convert your code to use late binding.
Here is a brief example of late binding, copied from Using early binding and late binding in Automation:
' Declare the object as a late-bound object
Dim oExcel As Object
Set oExcel = CreateObject("Excel.Application")
Note, if your code uses Excel named constants, you will need to substitute the constants' values for their names, or declare the constants in your code.

“User-defined type not defined” error in VB in Access 2007

I'm receiving a compile error on the following line of code:
Dim oXL As Excel.Application
The code is in VB in MS Access 2007. The line above is the beginning of a segment to generate an MS Excel file. The obvious answer to me was to ensure that the "Microsoft Office 12.0 Object Library" is checked under Tools > References. I've done this but the error persists. Does Excel need to be installed side-by-side for this to work? What have I done wrong? Thanks in advance.
You need to reference Microsoft Excel 12.0 Object Library or use late binding. Late binding is almost always necessary if you will be sharing your project with users who may have different versions of Excel installed.
For late binding, you would instead do:
Dim oXL as object
Set oXL = CreateObject("Excel.Application")
Then your code should work as expected, without the need to make the reference... assuming you aren't using any other Excel specific values or objects.

Import MS Word Form Field to Access - Missing Reference?

I am trying to import data into access 2007 from a MS Word form field.
I have followed the tutorial here: http://msdn.microsoft.com/en-us/library/aa155434(v=office.10).aspx
When I run the VBA code I get a compile error that says "User-defined type not defined". After doing some research I've found that it is likely because I am missing a reference to an object in an object library.
I have the following object libraries referenced:
Visual Basic For Applications
Microsoft Access 12.0 Object Library
Ole Automation
Microsoft Office 12.0 database engine Object library
Microsoft Word 12.0 Object library
The error is thrown when the sub is called here:
Sub GetWordData()
Am I missing a reference, or do I have another problem?
Thanks in advance
Ensure that you have set a reference to the Microsoft ActiveX Data Objects x.x Library.
In the code window, choose Tools->References, scroll to the library and tick it.
Note that using library references, rather than late binding (Create.Object("Word.Application")), makes it easier to access properties and methods but can mean that your code will not run in other environments.