473,668 Members | 2,580 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Compile Error: User Defined Type

34 New Member
I am currently trying to use the below VBA to import information into excel from access. This VBA is in the excle sheet:-

Expand|Select|Wrap|Line Numbers
  1.  Public Sub getrs() 
  2. Dim adoconn As ADODB.Connection
  3. Dim adors As ADODB.Recordset
  4. Dim sql As String
  5. Dim filenm As String
  6. sql = "Select * from Table1"
  7. filenm = "R:\HR\HR_System_Reports_Folder\Databases\HeadCount.mdb"
  8. Call GetCn(adoconn, adors, sql, filenm, "", "")
  9. Dim xlsht As Excel.Worksheet
  10. Set xlsht = Sheets("Sheet1")
  11. xlsht.Range("A1").CopyFromRecordset adors
  12. adors.Close
  13. adoconn.Close
  14. Set adors = Nothing
  15. Set adoconn = Nothing
  16. Set xlsht = Nothing
  17. End Sub
  18.  
However when I try to use this code it says Compile Error: User Defined Type Not Defined. Ibelieve I need to tick somethin in the references section but I do not know what. Has anyone got any ideas?
Dec 7 '07 #1
13 9061
Dököll
2,364 Recognized Expert Top Contributor
I am currently trying to use the below VBA to import information into excel from access. This VBA is in the excle sheet:-

Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Sub getrs()
  3. Dim adoconn As ADODB.Connection
  4. Dim adors As ADODB.Recordset
  5. Dim sql As String
  6. Dim filenm As String
  7. sql = "Select * from Table1"
  8. filenm = "R:\HR\HR_System_Reports_Folder\Databases\HeadCount.mdb"
  9. Call GetCn(adoconn, adors, sql, filenm, "", "")
  10. Dim xlsht As Excel.Worksheet
  11. Set xlsht = Sheets("Sheet1")
  12. xlsht.Range("A1").CopyFromRecordset adors
  13. adors.Close
  14. adoconn.Close
  15. Set adors = Nothing
  16. Set adoconn = Nothing
  17. Set xlsht = Nothing
  18. End Sub
  19.  
  20.  
However when I try to use this code it says Compile Error: User Defined Type Not Defined. Ibelieve I need to tick somethin in the references section but I do not know what. Has anyone got any ideas?
Are you doing this from Access, or Excel forrestgump?
Dec 7 '07 #2
forrestgump
34 New Member
Are you doing this from Access, or Excel forrestgump?
I am currently running this VBA in excel to try and pull the information from access.
Dec 7 '07 #3
ADezii
8,834 Recognized Expert Expert
I am currently trying to use the below VBA to import information into excel from access. This VBA is in the excle sheet:-

Public Sub getrs()
Dim adoconn As ADODB.Connectio n
Dim adors As ADODB.Recordset
Dim sql As String
Dim filenm As String
sql = "Select * from Table1"
filenm = "R:\HR\HR_Syste m_Reports_Folde r\Databases\Hea dCount.mdb"
Call GetCn(adoconn, adors, sql, filenm, "", "")
Dim xlsht As Excel.Worksheet
Set xlsht = Sheets("Sheet1" )
xlsht.Range("A1 ").CopyFromReco rdset adors
adors.Close
adoconn.Close
Set adors = Nothing
Set adoconn = Nothing
Set xlsht = Nothing
End Sub

However when I try to use this code it says Compile Error: User Defined Type Not Defined. Ibelieve I need to tick somethin in the references section but I do not know what. Has anyone got any ideas?
  1. You may be missing a Reference to the Microsoft Access XX.X Object Library, this could account for the Error.
  2. You should Instantiate the Object Variables pointing to the ADO Connection and Recordset Objects as in:
    Expand|Select|Wrap|Line Numbers
    1. 'Declarations
    2. Dim adoconn As ADODB.Connection
    3. Dim adors As ADODB.Recordset
    4.  
    5. 'Creation of New Object Instances
    6. Set adoconn = New ADODB.Connection
    7. Set adors = New ADODB.Recordset
  3. The problem may be with the GetCn Routine, namely:
    Expand|Select|Wrap|Line Numbers
    1. GetCn(adoconn, adors, sql, filenm, "", "")
  4. Can you post the code for this Routine. This would enable the entire process to be duplicated, and hopefully, enable a solution to your problem.
Dec 8 '07 #4
missinglinq
3,532 Recognized Expert Specialist
I think Adezii's first comment is at least an important part of the problem here! Anytime you get this error message and there isn't a user defined function involved, it means that there's a function Access assumes to be user-defined because it can't find it in any of the referenced libraries. This is either because the library isn't referenced or the fumction name is misspelled.

Welcome to TheScripts!

Linq ;0)>

P.S. I understand your frustration, Forrest! Everyone keeps yelling "Run, Forrest, run!" and the blasted code just won't run!
Dec 8 '07 #5
forrestgump
34 New Member
I think Adezii's first comment is at least an important part of the problem here! Anytime you get this error message and there isn't a user defined function involved, it means that there's a function Access assumes to be user-defined because it can't find it in any of the referenced libraries. This is either because the library isn't referenced or the fumction name is misspelled.

Welcome to TheScripts!

Linq ;0)>

P.S. I understand your frustration, Forrest! Everyone keeps yelling "Run, Forrest, run!" and the blasted code just won't run!
I have got it to run! here is the full code. I also needed to swuitch something on in the reference table.

Public Sub GetCn(ByRef dbcon As ADODB.Connectio n, ByRef dbrs As ADODB.Recordset , _
sqlstr As String, dbfile As String, usernm As String, pword As String)
Set dbcon = New ADODB.Connectio n
dbcon.Open "PROVIDER=Micro soft.Jet.OLEDB. 4.0;Data Source=" & dbfile & ";", _
usernm, pword
Set dbrs = New ADODB.Recordset
dbrs.Open sqlstr, dbcon
End Sub

Public Sub getrs()
Dim adoconn As ADODB.Connectio n
Dim adors As ADODB.Recordset
Dim sql As String
Dim filenm As String
sql = "Select * from table1"
filenm = "R:\HR\HR_Syste m_Reports_Folde r\Databases\Hea dCount.mdb"
Call GetCn(adoconn, adors, sql, filenm, "", "")
Dim xlsht As Excel.Worksheet
Set xlsht = Sheets("Sheet1" )
xlsht.Range("A1 ").CopyFromReco rdset adors
adors.Close
adoconn.Close
Set adors = Nothing
Set adoconn = Nothing
Set xlsht = Nothing
End Sub

I need to find a way of pulling multiple queries, stacked, with a blank line in between. Any ideas?
Dec 11 '07 #6
ADezii
8,834 Recognized Expert Expert
I have got it to run! here is the full code. I also needed to swuitch something on in the reference table.

Public Sub GetCn(ByRef dbcon As ADODB.Connectio n, ByRef dbrs As ADODB.Recordset , _
sqlstr As String, dbfile As String, usernm As String, pword As String)
Set dbcon = New ADODB.Connectio n
dbcon.Open "PROVIDER=Micro soft.Jet.OLEDB. 4.0;Data Source=" & dbfile & ";", _
usernm, pword
Set dbrs = New ADODB.Recordset
dbrs.Open sqlstr, dbcon
End Sub

Public Sub getrs()
Dim adoconn As ADODB.Connectio n
Dim adors As ADODB.Recordset
Dim sql As String
Dim filenm As String
sql = "Select * from table1"
filenm = "R:\HR\HR_Syste m_Reports_Folde r\Databases\Hea dCount.mdb"
Call GetCn(adoconn, adors, sql, filenm, "", "")
Dim xlsht As Excel.Worksheet
Set xlsht = Sheets("Sheet1" )
xlsht.Range("A1 ").CopyFromReco rdset adors
adors.Close
adoconn.Close
Set adors = Nothing
Set adoconn = Nothing
Set xlsht = Nothing
End Sub

I need to find a way of pulling multiple queries, stacked, with a blank line in between. Any ideas?
Please describe in greater detail.
Dec 11 '07 #7
forrestgump
34 New Member
Please describe in greater detail.
The code above pulls in one query, well actually one table 'table1', but lets say I also want to pull through 'table2' and 'table3' onto the worksheet and separate the results by a blank row??

I.e. I want to pull through 3 tables onto 1 worksheet and separate the results by a space.

Regards,

Forrest
Dec 13 '07 #8
ADezii
8,834 Recognized Expert Expert
The code above pulls in one query, well actually one table 'table1', but lets say I also want to pull through 'table2' and 'table3' onto the worksheet and separate the results by a blank row??

I.e. I want to pull through 3 tables onto 1 worksheet and separate the results by a space.

Regards,

Forrest
I imagine that it could be as simple as a Row insertion between each CopyFromRecords et.
Dec 13 '07 #9
james 125877
2 New Member
hi

i got a problem when i tried to compile it, i had an error and it:

The type or namespace name 'fclsViewer' could not be found (are you missing a using directive or an assembly reference?)

now the code is: using System;
using System.Collecti ons.Generic;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows. Forms;


namespace Picture_Viewer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeCompo nent();
}

private void button1_Click(o bject sender, EventArgs e)
{
Application.Run (new flcsViewer());
}

private void Form1_Load(obje ct sender, EventArgs e)
{
// Show the open file dialog box.
if (ofdSelectPictu re.ShowDialog() == DialogResult.OK )
{
//Load the picture into the picture box.
picShowPicture. Image = Image.FromFile( ofdSelectPictur e.FileName);
// Show the name of the file in the form's caption.
this.Text = String.Concat(" Picture Viewer (" + ofdSelectPictur e.FileName + ") ");
}

}
}
}


Please help me i really want it to work !!!
Dec 13 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
4739
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much appreciated. Thanks in advance
4
1984
by: Seok Bee | last post by:
Dear Experts, I've completed my console application and now wants to compile the application and an executable file to be run at another location. However, I've tried compiling that program in the command prompt with the following command : vbc Module1.vb /out:OEAutomation.exe /t:exe I received a lot of error messages.
8
2347
by: mastermagrath | last post by:
Hi, I'm about half way through Bruce Eckels thinking in C++ Vol 1. He gives a very short example of how compiler function name decoration helps remove subtle bugs by type-safe linkage. However, upon looking at the example i understand why it fails to link but don't understand why it even compiles. Here's the code, which split between 2 files Def.cpp and Use.cpp: //File Def.cpp
2
1626
by: john | last post by:
I'm trying to use the code below. But when the code is run I get: Compile error: an infotype defined by user is not defined. <dbClient As Databaseis then highlighted. Somebody an idea on how do I make this work? Thanks, john Private Sub CheckExists(strTableName As String) ' check to see if the table exists, if it does then delete it since the next
5
1517
by: Torben Laursen | last post by:
Hi Often I just want to compile one c++ file in a project the check it for errors. Now I can right click on a *.cpp file and select "Compile" But is there a way and short cut to compile a file of any type. luke *.cc, *.h, *hpp Thanks Torben
3
12057
by: blakerrr | last post by:
Hi everyone, I am trying to export a table to an excel file using vba on a form's button click event. I am getting the error: Compile error: User-defined type not defined. And it highlights my first line: Dim appExcel As Excel.Application Any ideas? I am using Access 2003, but I am using Access 2000 file format. Does this have to with DAO and ADO something-or-others? I'm a beginner with all of this database stuff so please...
2
4132
by: BruceWho | last post by:
I downloaded boost1.35.0 and built it with following command: bjam --toolset=msvc-7.1 --variant=release --threading=multi -- link=shared --with-system stage and it failed to compile, error message is: E:\software\development\boost_1_35_0\boost_1_35_0>bjam -- toolset=msvc-7.1 --variant=release --threading=multi --link=shared --
11
1758
by: Tim H | last post by:
The following program compiles just fine in C, but not in C++. Can anyone explain why? I have a chunk of code that defines stuff like this in headers (without the extern) that I can not easily change. The C compiler recognizes the first foo and second foo as the same. The C++ compiler not so much. Is there a way to get this to compile in C++ without changing all the headers?
1
3017
by: coolminded | last post by:
hello all, i'm using vb6 and sql. whenever i compile my project it shows the message "User-defined not defined". i have kept all the references associated with my project. even though, it shows the message. can anybody help me ??? TIA
0
8459
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8371
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8889
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8790
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...
0
8652
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7391
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 project—planning, coding, testing, and deployment—without 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
6206
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
4202
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1779
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.