 |

02-24-2005, 02:51 PM
|
|
Newcomer
|
|
Join Date: Aug 2004
Posts: 13
|
|
compiling error
|
I found a class module and form to incorparate into my database program, when I run the programm it works fine, but when I try to compile I get an error saying:
User defined typed not defined.
the orginal program I dl compiles fine, but since I add the form and class module to my project it does not compile, i get that error. Any help please Thanks
|
|

02-24-2005, 02:58 PM
|
|
Centurion
|
|
Join Date: Mar 2003
Location: Omaha, Nebraska
Posts: 197
|
|
|
Your program runs fine in debug mode most likely because the code path you took didn't execute a subroutine/function that uses the missing UDT. When you compile, it checks everything.
Try attaching the class module you downloaded. It's hard to know which UDT is missing without seeing the code itself.
Try it yourself though, and step through the class module's code and see what's missing.
|
|

02-24-2005, 03:33 PM
|
 |
Keeper of foo
Retired Moderator * Guru *
|
|
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
|
|
|
You're missing a Reference, and as Baaklar said, we can't tell what it is unless you attach the offending code.
|
__________________
~ Quod non mortiferum, fortiorem me facit ~
Avatar by lebb
|

02-24-2005, 05:20 PM
|
|
Newcomer
|
|
Join Date: Aug 2004
Posts: 13
|
|
Quote:
|
Originally Posted by angeleye1963
sorry, but how do i add the attachment here, I uploaded 2 times.
|
Here is the code:
If possible can I email someone the program to look at.
Code:
Private Const QS_MOUSEBUTTON As Long = &H4
Private Const QS_HOTKEY As Long = &H80
Private Const QS_KEY As Long = &H1
Private Const QS_PAINT As Long = &H20
Private Const QS_TIMER As Long = &H10
Private Declare Function GetQueueStatus Lib "user32" (ByVal qsFlags As Long) As Long
Private Function DoEventsEx() As Long
'DoEventsEx is tested and is believed to be 100% to 800% faster then
'DoEvents. For more info, search planetsourcecode.com in the VBWorld for:
'DoEvents evolution
On Error Resume Next
DoEventsEx = GetQueueStatus(QS_HOTKEY Or QS_KEY Or QS_MOUSEBUTTON Or QS_PAINT Or QS_TIMER)
If DoEventsEx <> 0 Then
DoEvents
End If
End Function
Public Sub ExportToCSV(ADODBRecordset As ADODB.Recordset, FilePathToExport As String, ShowProgress As ProgressBar)
Dim iTotalRecords As Long, i As Long, NumberofFields As Long
Dim Progress As Boolean, TotalRecords As Long
On Local Error Resume Next 'Some recordsets can be pretty big
'that's why I used long and not integer
Open FilePathToExport For Output Access Write As #1
With ADODBRecordset
NumberofFields = .Fields.Count - 1 'It is faster to read from
.MoveFirst 'memory then executing operation
'in a loop
For i = 0 To NumberofFields 'Now add the field names similar
Print #1, .Fields(i).Name & ","; 'to the ones below
Next i
Print #1, 'Go to next line
With ShowProgress
.Min = 0
.Max = ADODBRecordset.RecordCount
.Value = 0
End With 'SHOWPROGRESS
Do While Not .EOF
TotalRecords = TotalRecords + 1
For i = 0 To NumberofFields 'If there is an emty field,
If (IsNull(.Fields(i))) Then 'add a , to indicate it is
Print #1, ","; 'empty
Else '(ISNULL(.FIELDS(I))) = FALSE/0
If i = NumberofFields Then
Print #1, Chr$(34) & Trim$(CStr(.Fields(i))) & Chr$(34);
Else 'NOT I...
Print #1, Chr$(34) & Trim$(CStr(.Fields(i))); Chr$(34) & ",";
End If
End If 'Putting data under "" will not
Next i 'confuse the reader of the file
DoEventsEx 'between Dhaka, Bangladesh as two
Print #1, 'fields or as one field .
.MoveNext 'Chr(34) is doublequote
ShowProgress.Value = ShowProgress.Value + 1
Loop
End With 'ADODBRECORDSET
Close #1
End Sub
Public Sub ExportToExcel(ADODBRecordset As ADODB.Recordset, ShowProgress As ProgressBar)
Dim i As Integer, iRowIndex As Integer, avRows As Variant
Dim iColIndex As Integer, iRecordCount As Integer, objTemp As Object
Dim iFieldCount As Integer, xCELver As Byte, [U]objExcel As Excel.Application[/U]this is the offending line.
On Local Error Resume Next
With ShowProgress
.Min = 0
.Max = ADODBRecordset.RecordCount
.Value = 0
End With 'SHOWPROGRESS
With ADODBRecordset
.MoveFirst
avRows = .GetRows() 'Read all the records
iRecordCount = UBound(avRows, 2) + 1 'in an array and
iFieldCount = UBound(avRows, 1) + 1 'determine how many
'fields in an array
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
'Ensure Excel remains visible if we change to active sheet
Set objTemp = objExcel
If xCELver >= 8 Then
Set objExcel = objExcel.ActiveSheet
End If
iRowIndex = 1
iColIndex = 1
'Place Name of the fields
For iColIndex = 1 To iFieldCount 'As coloumn headers with
With objExcel.Cells(iRowIndex, iColIndex) 'a better font then Sans
.Value = ADODBRecordset.Fields(iColIndex - 1).Name 'Serif
With .Font
.Name = "Tahoma"
.Bold = True
.Size = 9
End With '.FONT
End With 'OBJEXCEL.CELLS(IROWINDEX,
Next iColIndex
End With 'ADODBRECORDSET
With objExcel 'Go Baby GO! Add DATA!
For iRowIndex = 2 To iRecordCount + 1 'BEAUTIFUL DATA!
For iColIndex = 1 To iFieldCount 'MY DATA!
.Cells(iRowIndex, iColIndex) = avRows(iColIndex - 1, iRowIndex - 2)
ShowProgress.Value = iRowIndex
DoEventsEx
Next iColIndex
Next iRowIndex
.Cells(1, 1).CurrentRegion.EntireColumn.AutoFit 'Autofit for good looks
End With 'OBJEXCEL
End Sub
Public Sub ExportToHTML(ADODBRecordset As ADODB.Recordset, FilePathToExport As String, TitleOfHTML As String, ShowProgress As ProgressBar)
Dim TotalRecords As Long, i As Integer, Progress As Boolean
Dim NumberofFields As Long
On Local Error Resume Next
Open FilePathToExport For Output As #1
Print #1, "<HTML><HEAD><TITLE> " & TitleOfHTML & " </TITLE></HEAD>"
Print #1, "<BODY BGCOLOR=""FFFFFF"">"
Print #1, "<TABLE BGCOLOR=""00AAFF"" WIDTH=""100%"">"
Print #1, "<TR><TD>"
Print #1, "<FONT FACE=ARIAL SIZE+=3><B>" & TitleOfHTML & "</B></font></td></tr>"
Print #1, "<TR>"
'First add all the usual
With ADODBRecordset 'HTML Tags to the ASCII
.MoveFirst 'File (with color).
For i = 0 To .Fields.Count - 1
Print #1, "<TD BGCOLOR=CCCCC>" 'Now add the titles to the
Print #1, "<B>"; .Fields(i).Name; "</B>" 'file. Make sure they
Print #1, "</TD>" 'Stand out.
Next i
Print #1, "</TR>"
.MoveFirst
With ShowProgress
.Min = 0
.Max = ADODBRecordset.RecordCount
.Value = 0
End With 'SHOWPROGRESS
Do While Not .EOF
Print #1, "<TR>" 'Add database records in HTML Format
For i = 0 To .Fields.Count - 1
Print #1, "<TD BGCOLOR=CCCCC>"
Print #1, .Fields(i); " " 'I am having problem
Print #1, "</TD>" 'appending null values
DoEventsEx 'Mail your suggestion
Next i 'to [email]elv15@toughguy.net[/email]
Print #1, "</TR>"
.MoveNext
ShowProgress.Value = ShowProgress.Value + 1
Loop
End With 'ADODBRECORDSET
Print #1, "</TABLE></BODY></HTML>" 'Complete the ASCII HTML
Close #1 'File
End Sub
|
Last edited by lebb; 02-24-2005 at 09:24 PM.
|

02-24-2005, 06:50 PM
|
 |
Retread
Retired Moderator * Expert *
|
|
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,742
|
|
|
Did you remember to reference the Excel Object Library? (Project > References > ...)
|
|

02-25-2005, 09:50 AM
|
|
Newcomer
|
|
Join Date: Aug 2004
Posts: 13
|
|
Quote:
|
Originally Posted by MikeJ
Did you remember to reference the Excel Object Library? (Project > References > ...)
|
No I did not do that, but I do not see the excel object library in the list, is there another library that I must use.
|
|

02-25-2005, 09:53 AM
|
|
Newcomer
|
|
Join Date: Aug 2004
Posts: 13
|
|
Quote:
|
Originally Posted by angeleye1963
No I did not do that, but I do not see the excel object library in the list, is there another library that I must use.
|
ok, I found it, and I can know compile without any error, Can you explain what and why I needed to reference that object, I sure would appreciate it. Thanks for the help Lori
|
|

02-25-2005, 10:19 AM
|
|
Junior Contributor
|
|
Join Date: Feb 2005
Posts: 247
|
|
Because of this line
Code:
Dim iFieldCount As Integer, xCELver As Byte, objExcel As Excel.Application
|
|

02-25-2005, 11:54 AM
|
 |
Ultimate Contributor
Forum Leader * Expert *
|
|
Join Date: Feb 2004
Location: New Jersey
Posts: 3,338
|
|
|
To expand on that, while your PC "knows about" the Excel DLL installed on your machine, your default VB application doesn't. In order to use the functionality of a DLL that you see in Project --> References, you need to check the box to make the VB program "aware" of the DLL. Once that is done, like with Excel in this case, you can use all of the functionality that the DLL offers.
|
__________________
DON'T CLICK HERE
Useful forum tags: [VB][/VB], [CODE][/CODE], [HTML][/HTML]
|

02-25-2005, 04:36 PM
|
|
Newcomer
|
|
Join Date: Aug 2004
Posts: 13
|
|
Quote:
|
Originally Posted by HardCode
To expand on that, while your PC "knows about" the Excel DLL installed on your machine, your default VB application doesn't. In order to use the functionality of a DLL that you see in Project --> References, you need to check the box to make the VB program "aware" of the DLL. Once that is done, like with Excel in this case, you can use all of the functionality that the DLL offers.
|
Ok, so DLL are commonly used procedures, already coded for Vb to use, then I only have to call the DLL to be used in any of my produres. I am embedding or link the excel object, I have a reference of the link object, but the object is actually kept in other applications.
|
|

02-25-2005, 04:40 PM
|
|
Newcomer
|
|
Join Date: Jan 2005
Location: Moss, Norway, Europe
Posts: 8
|
|
|
I always add the line
Option Explicit
In the top of every form and module. Good rule of thumb.
//theHollow
|
|

02-25-2005, 06:51 PM
|
 |
Keeper of foo
Retired Moderator * Guru *
|
|
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
|
|
|
You know VB can be set to always add it for you.... better rule of thumb.
|
__________________
~ Quod non mortiferum, fortiorem me facit ~
Avatar by lebb
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|