Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compile Error in VB Function 1

Status
Not open for further replies.

quest4

Technical User
Aug 27, 2001
735
US
I have a Public function running through autoexec macro, so every time I opem my Acess database I get this error. The error says:
Compile Error: User-Defined Type not Defined.

In the debugger the line Dim dbs As Database is high-lited. Here is the top of my code:

Public Function RunOncez()
Dim dbs As Database <- This is high-lited
Dim rst As Recordset
Dim strSQL
Set dbs = CurrentDb

Now, I am no VB guru, in fact I am just starting to learn about it, but this looks like just about every example that I have seen in MS Help. What on earth is the debugger trying to tell me? Thanks a lot to anyone who helps straighten this out.
 
Hi!

Access is trying to tell you that you need to set a reference to the DAO object library. While in the VB window click on Tools on the menu bar and choose References. Find the reference to the DAO 3.6 object library and check the box beside it.

hth
Jeff Bridgham
 
Ok, that worked for that line, but I got a run-Time error: 13 Type mismatch on a line in the middle. Here is the whole function:
Public Function RunOncez()
Dim dbs As Database
Dim rst As Recordset
Dim strSQL
Set dbs = CurrentDb
strSQL = &quot;SELECT Max(Format([date],&quot; & Chr(34) & &quot;yyyy&quot; & Chr(34) & &quot;)) AS Year FROM tblDates&quot;
Set rst = dbs.OpenRecordset(strSQL) <-Run-Time Error
If Format(Now(), &quot;yyyy&quot;) <> rst.Fields(0).Value Then
With rst
.AddNew
.Fields(0).Value = Now()
.Update
End With
DoCmd.OpenQuery (“qryUpDateVacations”)
Else
End If
End Function

I get the new error on the Set rst. What on earth is wrong with it? Thank you for your quick response and your help.
 
Hi again!

I'm guessing that you are in Access2K. Go back to the references and select the reference to the DAO library. Now use the arrow buttons beside the list box to move the DAO reference up until it is above the ADO reference. Alternatively, or additionally, you can explicitly declare your variables as DAO.Database or DAO.Recordset.

hth
Jeff Bridgham
 
Ok, I tried adding the ADO, and got the same thing. Yes ai am running in Access 2000. Thank you for the quick reponse and the help.
 
I just had a hard time under standing what you want me to do, but after I re-read it a couple of time I finally figured up the priority keys and everything. NOW IT WORKS. Thank you very much for all of your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top