Solved

Error Compiling a function

Posted on 2002-07-24
8
1,333 Views
Last Modified: 2012-06-21
Hello experts,

I copied a startup() function into the database that I'm Working on right now.  This function gets the user's NT userID and other misc. info and then uses it to do some security.  

When I imported the function and tried to test it I got the following error:

"There was an error compiling a function"

The Visual Basic module contains a syntax error - check the code and then recompile it"

The function runs fine on the database that I imported it from.  Below is the VB for the function and I put the line that the compile bites on in quotes.

Option Compare Database
Option Explicit

Declare Function API_GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Declare Function GetComputerName& Lib "KERNEL32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long)

Global gbUpdateUser As Boolean
Global gsSQL        As String
Dim msUserID        As String
Dim msSQL           As String

Dim mRS             As Recordset
"Dim mDB             As Database"

Public Function Startup() As Boolean
    gbUpdateUser = False
    msUserID = GetUserName()
    Set mDB = CurrentDb
   
    CaptureLogin
   
    msSQL = "SELECT * FROM tblUsers WHERE tblUsers.NTID= '" & msUserID & " ';"
    Set mRS = mDB.OpenRecordset(msSQL, dbOpenSnapshot)
   
    With mRS
        If Not .EOF Then
            .MoveLast
            If .RecordCount > 0 _
            And !admin = True Then
                gbUpdateUser = True
            End If
        End If
        .Close
    End With
   
    mDB.Close
    Set mRS = Nothing
    Set mDB = Nothing
   
    MsgBox "Welcome to the Problem Report Database", vbInformation + vbOKOnly, "Welcome"
   
End Function

Does anyone have any idea why this would happen on the new database and not on the one I copied it from.  I'm using Access2000 and Windows2000.  Thanks very much.  

P.S I didn't paste in the entire code so if you wonder why something might be missing.....
   
0
Comment
Question by:tdenny
  • 5
  • 2
8 Comments
 

Author Comment

by:tdenny
Comment Utility
sorry I forgot to add this.  When I run the debug - compile I get the following message Compile Error user defined type not defined and the dimMDB as Database gets highlighted.
0
 
LVL 11

Accepted Solution

by:
joekendall earned 100 total points
Comment Utility
You need to make a reference to the DAO 3.6 Library. You can go into a code module and select Tools - References. There you can set the reference.

With Access 2000, the reference is not automatically set.

Thanks!

Joe
0
 

Author Comment

by:tdenny
Comment Utility
Joe,

Thanks I'll most certainly give you credit for that.  One more little question though - your response got me by the first compile error now I get one for the code below:  The line that says .Edit below gets a compile error that says method or data member not found.  Do I have another library that I need to add?  Thanks much for clearing the first hurdle.

Private Sub CaptureLogin()
  Dim sERMS As String
 
  sERMS = CurrentERMS()
 
  DoCmd.SetWarnings False
  msSQL = "SELECT * FROM tblLogons WHERE UserID = '" & msUserID & "'"
 
  Set mRS = mDB.OpenRecordset(msSQL, dbOpenDynaset)
 
  If mRS.EOF Then
    msSQL = "INSERT INTO tblLogons ( UserID, ERMS, LastOn ) " & _
            "SELECT '" & msUserID & "' AS UserID, '" & sERMS & "' AS ERMS, #" & Date & "# AS LastOn"
    DoCmd.RunSQL msSQL
  Else
    With mRS
      .Edit
      !laston = Date
      !ERMS = sERMS
      .Update
    End With
  End If
  DoCmd.SetWarnings True
End Sub
0
 
LVL 11

Expert Comment

by:joekendall
Comment Utility
Is mRS dimensioned as a variable?
0
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 

Author Comment

by:tdenny
Comment Utility
Yes it is dimensioned in the code up top.
0
 
LVL 44

Expert Comment

by:Arthur_Wood
Comment Utility
make sure the mRS is Dimmed as a DAO.Recordset.  If you are running Access 2000, the default Recordset type is ADO.

Dim mRS as DAO.Recordset

Arthur Wood
0
 

Author Comment

by:tdenny
Comment Utility
Arthur,

That did it.  Thanks much.
0
 

Author Comment

by:tdenny
Comment Utility
Joe, Arthur,

Thanks to you both for the expertise.  As always you guys are great.  Much appreciated.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now