Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Compile error: user-type not defined

Posted on 2007-03-22
9
Medium Priority
?
382 Views
Last Modified: 2012-08-13
Hi Experts!

I can't get my code running in the module I created. I get this message from the compiler "User-defined type not defined". I thought that I forgot to define another variable, but everything seems fine. The error message highlights the command "Function ExportToExcel()" in yellow.

That's the code:
Function ExportToExcel()

    Dim Db As DAO.Database
    Dim rst As DAO.Recordset, RstDay As DAO.Recordset
    Dim appexcel As Object  'Excel.Application
    Dim wbexcel As Object   'Excel.Workbook
   
    Dim I As Integer, j As Integer
    Set Db = CurrentDb
   
    Set RstDay = Db.OpenRecordset("Select Distinct EventDay From TblCalendar")
'    Set RstDay = Db.OpenRecordset("SELECT TblCalendar.EventDay, '~' & [DirectorateID] & '~' & [Calendar_E] AS Expr1, TblCalendar.StatID FROM TblCalendar ORDER BY TblCalendar.EventDay DESC , TblCalendar.StatID;")
   
    Set appexcel = CreateObject("Excel.Application")
    appexcel.Visible = True
    Set wbexcel = appexcel.Workbooks.Open("C:\Documents and Settings\mconea\My Documents\Base de données\Exemples\EMS RO Calendar Excel.xls")
    'Set wbexcel = appexcel.Workbooks.Open("C:\EMS Calendar Excel.xls")

    appexcel.Sheets("Sheet1").Select
   
       
    Do Until RstDay.EOF
        'I = 4
        ' Search of the column to fill
        Select Case RstDay("EventDay")
            Case 36: j = 1
            Case 35: j = 2
            Case 34: j = 3
            Case 33: j = 4
            Case 32: j = 5
            Case 31: j = 6
            Case 30: j = 7
            Case 29: j = 1
            Case 28: j = 2
            Case 27: j = 3
            Case 26: j = 4
            Case 25: j = 5
            Case 24: j = 6
            Case 23: j = 7
            Case 22: j = 1
            Case 21: j = 2
            Case 20: j = 3
            Case 19: j = 4
            Case 18: j = 5
            Case 17: j = 6
            Case 16: j = 7
            Case 15: j = 1
            Case 14: j = 2
            Case 13: j = 3
            Case 12: j = 4
            Case 11: j = 5
            Case 10: j = 6
            Case 9: j = 7
            Case 8: j = 1
            Case 7: j = 2
            Case 6: j = 3
            Case 5: j = 4
            Case 4: j = 5
            Case 3: j = 6
            Case 2: j = 7
            Case 1: j = 1
            Case 0: j = 2
            Case -1: j = 3
            Case -2: j = 4
            Case -3: j = 5
            Case -4: j = 6
            Case -5: j = 7
            Case -6: j = 1
            Case -7: j = 2
            Case -8: j = 3
            Case -9: j = 4
            Case -10: j = 5
            Case -11: j = 6
            Case -12: j = 7
            Case -13: j = 1
            Case -14: j = 2
            Case -15: j = 3
            Case -16: j = 4
            Case -17: j = 5
            Case -18: j = 6
            Case -19: j = 7
           
        End Select
       
        Select Case RstDay("EventDay")
          Case 29, 28, 27, 26, 25, 24, 23
            I = 32
          Case 22, 21, 20, 19, 18, 17, 16
            I = 49
          Case 15, 14, 13, 12, 11, 10, 9
            I = 66
          Case 8, 7, 6, 5, 4, 3, 2
            I = 83
          Case 1, 0, -1, -2, -3, -4, -5
            I = 101
          Case -6, -7, -8, -9, -10, -11, -12
            I = 111
          Case -13, -14, -15, -16, -17, -18, -19
            I = 128
          Case Else
            I = 13
                   
        End Select
       
        LastLigne = False
       
        Do Until LastLigne
             If appexcel.Cells(I, j) <> "" Then ' if the row is not empty, the line advances
                I = I + 1
            Else
                LastLigne = True
            End If
        Loop
       
        Set rst = Db.OpenRecordset("Select * From TblCalendar Where EventDay='" & RstDay("EventDay") & "'")
       
        Do Until rst.EOF
            appexcel.Cells(I, j) = rst![BotStat]
            I = I + 1
            rst.MoveNext
        Loop
        RstDay.MoveNext
    Loop
   
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing

End Function

Hope someone can find out

Thanks

stronghold888
0
Comment
Question by:stronghold888
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
9 Comments
 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 600 total points
ID: 18775327
Are you setting anything equal to some variable you have not defined (Dimmed)?
If Option Explicit is not present in the Declarations section of EVERY module, it's quite easy to set something equal to a variable that was never defined. By default, Option Explicit is not turned - unless you have 'explicity (no pun) set the "Require Variable Declaration' checkbox under Tools>>Options in the VBA editor.

So ... this is a good thing to check. IF ... you find it is not present in a given module, the put it in. Once it's in every module ... then do a Compile.  If there are any undefined variables ... they will now be exposed.

And of course ... check to see that there are no missing References  *MISSING ... will show if any are missing

mx
0
 
LVL 75
ID: 18775340
PS ...  this exact same error was just posted a few minutes ago by another person ... So ... I did a quick copy and paste :-)

mx
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 18775352
if you happened to name your module ExportToExcel
better rename it something like

modExportToExcel

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 4

Author Comment

by:stronghold888
ID: 18775447
Forgot to declare some variables in Tools/References. Now there's just one error message with this line "Set rst = Db.OpenRecordset("Select * From TblCalendar Where EventDay='" & RstDay("EventDay") & "'")"

capricorn1, change the export name to another name it does not work either

stronghold888
0
 
LVL 4

Author Comment

by:stronghold888
ID: 18775474
Just found out...I changed the "EventDay" type from Number to Text and now it works. Only thing, EventDay is a field conaining numbers, not text...so I think that I have to change the last line "Set rst = Db.OpenRecordset("Select * From TblCalendar Where EventDay='" & RstDay("EventDay") & "'")" to something different.
I just removed the "Distinct" from this line Set RstDay = Db.OpenRecordset("Select Distinct EventDay From TblCalendar")...but the last line does not work and I don't know how I can change it :(
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 1400 total points
ID: 18775487
if you want eventday as number

Set rst = Db.OpenRecordset("Select * From TblCalendar Where EventDay=" & RstDay("EventDay"))
0
 
LVL 4

Author Comment

by:stronghold888
ID: 18775534
It works now.

Thanks a lot! :o)

stronghold888
0
 
LVL 75
ID: 18775616
Hey Cap ... can we go for 3 today on this error :-)

Thanks stronghold ...

mx
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 18775680
just  wait..... <lol>
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question