473,669 Members | 2,523 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB compile error User defined Object

alpnz
113 New Member
I am getting a Compile error on the following Code.
What have I missed

Expand|Select|Wrap|Line Numbers
  1. Private Sub create_eplab_Click()
  2. ' First sort out the variables. Including label content, quantity to print etc
  3.  
  4.  
  5.     Dim var1 As String
  6.     Dim var2 As String
  7.     Dim var3 As String
  8.     Dim var4 As String
  9.     Dim var5 As String
  10.  
  11. ' Sort out where the data is coming from. Aim for reusable code
  12.  
  13.     Dim mydb As Database, myset As Recordset
  14.     Dim sql_rst As String
  15.  
  16.  
  17.    sql_rst = "SELECT * FROM qry_elabel"
  18.  
  19.     Set mydb = CurrentDb
  20.     Set myset = mydb.OpenRecordset(sql_rst)
  21. ' Declare the variables values
  22.  
  23.     var1 = myset![var1]
  24.     var2 = myset![var2]
  25.     var3 = myset![var3]
  26.     var4 = myset![var4]
  27.     var5 = myset![var5]
  28.     Const quote As String = """"
  29.  
  30. ' Code each label combination required
  31.  
  32.     Dim lab1 As String
  33.  
  34. lab1 = "N" & vbCrLf _
  35.         & "S4" & vbCrLf _
  36.         & "A30,30,0,5,1,1,N," & quote & [var1] & quote & vbCrLf _
  37.         & "A30,70,0,4,1,1,N," & quote & [var2] & quote & vbCrLf _
  38.         & "A30,135,0,4,1,1,N," & quote & [var3] & quote & vbCrLf _
  39.         & "B560,425,1,E30,1,2,160,B," & quote & [var4] & quote & vbCrLf _
  40.         & "A300,300,0,4,1,1,N," & quote & [var5] & quote & vbCrLf _
  41.         & "P1" & vbCrLf
  42.  
  43.  
  44. ' Print the label to the printer.
  45.  
  46. Open "COM2:" For Output As #1
  47.        Print #1, lab1
  48.  
  49. Close #1
  50.  
  51. End Sub
  52.  
  53.  
It debugs to the Dim mydb As Database , myset As Recordset Line.

What am I missing here?.

John S
Jan 14 '07 #1
22 7804
alpnz
113 New Member
The qry_elabel is as below.

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT PakTrak.PakTrakID, [Entity] & " - " & [RGN] AS var1, [VarietyDesc] & " " & [VGroup] AS var2, Sizing.SizeCode AS var3, "942001351234" AS var4, Runs.[RunCode] & "-" & [PakTrakID] AS var5
  3. FROM VGroup INNER JOIN (Variety INNER JOIN (Sizing INNER JOIN ((Entity INNER JOIN Runs ON Entity.EntityID = Runs.EntityID) INNER JOIN (Packaging INNER JOIN PakTrak ON Packaging.PackageingID = PakTrak.PackageingID) ON Runs.rn_id = PakTrak.rn_id) ON Sizing.SizeID = PakTrak.SizeID) ON Variety.VarietyID = Runs.VarietyID) ON (Runs.VGroupID = VGroup.VGroupID) AND (VGroup.VGroupID = Variety.VGroupID) AND (VGroup.VGroupID = Sizing.VGroupID)
  4. WHERE (((PakTrak.PakTrakID)=[Forms]![Pallet]![line_list_pal]));
  5.  
  6.  
Basically it sets up the text for a label, based on a selection in a listbox on the controlling form.

Any help very gratefully received.
John S
Jan 14 '07 #2
alpnz
113 New Member
The error is

"User-defined type Not defined" and the mydb As Database is highlighted.

The Data tables are linked via ODBC, the qry_elabel consolidates data from various tables to create text strings for each variable in the label.

John S
Jan 14 '07 #3
ADezii
8,834 Recognized Expert Expert
The error is

"User-defined type Not defined" and the mydb As Database is highlighted.

The Data tables are linked via ODBC, the qry_elabel consolidates data from various tables to create text strings for each variable in the label.

John S
Make sure that the proper Type Libraries are defined in the References Dialog, e.g. Microsoft DAO 3.6 Object Library, Microsoft ActiveX Data Objects 2.X Library, etc.

Explicitly Declare the Type Libraries to which Objects belong, e.g.
Dim MyDB As DAO.Database,
Dim MyRS As DAO.Recordset,
Dim YourRS As ADODB.Recordset , etc.

Hope this helps.
Jan 14 '07 #4
NeoPa
32,569 Recognized Expert Moderator MVP
You can also use Auto-Completion.
After typing "Dim MyDB As DAO.Datab" hit Ctrl-Space. If it can find the Database object in that object it will list it. If it is not listed then you don't have the correct library (reference) listed.
Jan 14 '07 #5
alpnz
113 New Member
Such a simple thing. Why is it selected in the development database, I certainly did not select it?.

The code now debus to the mydb.OpenRecord set(sql_rst) line. I wonder why not refer directly to mydb."qry_elabe l" as the recordset.
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub create_eplab_Click()
  3. ' First sort out the variables. Including label content, quantity to print etc
  4.  
  5.  
  6.     Dim var1 As String
  7.     Dim var2 As String
  8.     Dim var3 As String
  9.     Dim var4 As String
  10.     Dim var5 As String
  11.     Dim qty As Integer
  12. ' Sort out where the data is coming from. Aim for reusable code
  13.  
  14.     Dim mydb As DAO.Database, myset As DAO.Recordset
  15.     Dim sql_rst As String
  16.  
  17.  
  18.    sql_rst = "SELECT * FROM qry_elabel"
  19.  
  20.  
  21.     Set mydb = CurrentDb()
  22.     Set myset = mydb.OpenRecordset(sql_rst)
  23.  
  24. ' Declare the variables values
  25.  
  26.     var1 = myset![var1]
  27.     var2 = myset![var2]
  28.     var3 = myset![var3]
  29.     var4 = myset![var4]
  30.     var5 = myset![var5]
  31.     Const quote As String = """"
  32.  
  33. ' Code each label combination required
  34.     qty = Int(InputBox("How many labels for the selected line do you wish to print?", "No of Labels"))
  35.     Dim lab1 As String
  36.  
  37. lab1 = "N" & vbCrLf _
  38.         & "S4" & vbCrLf _
  39.         & "A30,30,0,5,1,1,N," & quote & [var1] & quote & vbCrLf _
  40.         & "A30,70,0,4,1,1,N," & quote & [var2] & quote & vbCrLf _
  41.         & "A30,135,0,4,1,1,N," & quote & [var3] & quote & vbCrLf _
  42.         & "B560,425,1,E30,1,2,160,B," & quote & [var4] & quote & vbCrLf _
  43.         & "A300,300,0,4,1,1,N," & quote & [var5] & quote & vbCrLf _
  44.         & "P" & quote & [qty] & quote & vbCrLf
  45.  
  46.  
  47. ' Print the label to the printer.
  48.  
  49. Open "COM2:" For Output As #1
  50.        Print #1, lab1
  51.  
  52. Close #1
  53.  
  54. End Sub
  55.  
  56.  
Jan 14 '07 #6
NeoPa
32,569 Recognized Expert Moderator MVP
Such a simple thing. Why is it selected in the development database, I certainly did not select it?
I think this means that ADezii's answer enabled the problem to be fixed.
The code now debugs to the mydb.OpenRecord set(sql_rst) line. I wonder why not refer directly to mydb."qry_elabe l" as the recordset.
That would seem to be a more straightforward way of doing it certainly.
Jan 14 '07 #7
alpnz
113 New Member
I think this means that ADezii's answer enabled the problem to be fixed.
That would seem to be a more straightforward way of doing it certainly.
Adrian,
Would that be the more sensible way to define the recordset. As you know I do not do enough of this to be conversant, in the howto. I might have done it long ago, does not mean I know how to do it now. :-)

John S
Jan 15 '07 #8
alpnz
113 New Member
At presant the code bombs out I think due to me not defining the data source correctly. The code at the moment.
Expand|Select|Wrap|Line Numbers
  1. Private Sub create_eplab_Click()
  2. ' First sort out the variables. Including label content, quantity to print etc
  3.  
  4.  
  5.     Dim var1 As String
  6.     Dim var2 As String
  7.     Dim var3 As String
  8.     Dim var4 As String
  9.     Dim var5 As String
  10.     Dim qty As Integer
  11. ' Sort out where the data is coming from. Aim for reusable code
  12.  
  13.     Dim mydb As Database
  14.     Dim myset As Recordset
  15.  
  16.     Dim rst As String
  17.  
  18.  
  19.  
  20.     rst = "SELECT * FROM [qry_elabel]"
  21.  
  22.  
  23.  
  24.     Set mydb = CurrentDb()
  25.     Set myset = mydb.OpenRecordset(rst)
  26.  
  27. ' Declare the variable data values
  28.  
  29.     var1 = myset![v1]
  30.     var2 = myset![v2]
  31.     var3 = myset![v3]
  32.     var4 = myset![v4]
  33.     var5 = myset![v5]
  34.  
  35.     Const quote As String = """"
  36.  
  37. ' Code each label combination required
  38.     qty = Int(InputBox("How many labels for the selected line do you wish to print?", "No of Labels"))
  39.     Dim lab1 As String
  40.  
  41. lab1 = "N" & vbCrLf _
  42.         & "S4" & vbCrLf _
  43.         & "A30,30,0,5,1,1,N," & quote & [var1] & quote & vbCrLf _
  44.         & "A30,70,0,4,1,1,N," & quote & [var2] & quote & vbCrLf _
  45.         & "A30,135,0,4,1,1,N," & quote & [var3] & quote & vbCrLf _
  46.         & "B560,425,1,E30,1,2,160,B," & quote & [var4] & quote & vbCrLf _
  47.         & "A300,300,0,4,1,1,N," & quote & [var5] & quote & vbCrLf _
  48.         & "P" & quote & [qty] & quote & vbCrLf
  49.  
  50.  
  51. ' Print the label to the printer.
  52.  
  53. Open "COM2:" For Output As #1
  54.        Print #1, lab1
  55.  
  56. Close #1
  57.  
  58. End Sub
  59.  
  60.  
"qry_elabel " is a query that consolidates various fields from multiple tables into 5 variables for the label. v1,v2,v3,v4,v5 the tables are linked tables from another Access Database, that just has tables in it. Can someone patiently explain where I am going wrong. It Halts at the myset = mydb.OpenRecord set(rst), with A Not enough operators in statement message. (I assume the sql SELECT statement).

Not much chop without data :-)

John S
Jan 15 '07 #9
MMcCarthy
14,534 Recognized Expert Moderator MVP
John

Just try ...

Expand|Select|Wrap|Line Numbers
  1.  
  2.     Dim mydb As Database
  3.     Dim myset As DAO.Recordset ' Just a precaution
  4.  
  5.     Set mydb = CurrentDb()
  6.     Set myset = mydb.OpenRecordset("qry_elabel")
  7.  
  8.  
Mary
Jan 15 '07 #10

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

Similar topics

0
1632
by: Xiaofeng Zhang | last post by:
when I compile my project setting, there are many LINK errors. But when I compile my project under debug setting, everything is OK. How can I deal with it? The errors is followed. Linking... LIBCMT.lib(crt0dat.obj) : error LNK2005: _exit already defined in msvcrt.lib(MSVCR71.dll) LIBCMT.lib(crt0dat.obj) : error LNK2005: __exit already defined in msvcrt.lib(MSVCR71.dll)
17
3121
by: newbiecpp | last post by:
I have hard time to understand run-time environment. Let assume that I have a program that has a simple variable alpha. When this variable is statically allocated, the compiler can use the absolute address of alpha to access to it. What confuses me is that when the variable is dynamically allocated, how does the compiler implement it? We know the address of the variable until run-time. During the compilation, how can we access to the...
10
4450
by: Jean-David Beyer | last post by:
I have some programs running on Red Hat Linux 7.3 working with IBM DB2 V6.1 (with all the FixPacks) on my old machine. I have just installed IBM DB2 V8.1 on this (new) machine running Red Hat Enterplise Linux 3 ES, and applied FixPack fp5_mi00069.tar to it. After creating an instance, starting the database, creating a database, and entering the table definitions, all of which seems to work OK, I entered a tiny 8-row table and can do...
4
21551
by: Monte | last post by:
It compiles fine in one of my ms2002 databases, but on another db (I inherited from somebody else), I get this compile error: "User-defined type not defined" Is something turned off in this second db or something? Thanks much
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
8
2348
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
10
2025
by: B Williams | last post by:
I have been working with this code for a better part of the day and I can't figure out where I am making a mistake. I can only imagine it is when I declare multiple paramaters on the constructor because the program compiles with just one parameter. Can someone look at this and tell me where I made my error? This is the error I get while trying to compile. error C2664: 'GradeBook::GradeBook(const GradeBook &)' : cannot convert...
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
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...
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?
0
8466
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
8384
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
8810
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
8590
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,...
1
6211
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
5683
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();...
0
4208
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...
0
4387
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2798
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

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.