Solved

Error Compiling a function

Posted on 2002-07-24
8
1,396 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
ID: 7174846
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
ID: 7175003
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
ID: 7175112
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 11

Expert Comment

by:joekendall
ID: 7175224
Is mRS dimensioned as a variable?
0
 

Author Comment

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

Expert Comment

by:Arthur_Wood
ID: 7175302
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
ID: 7175309
Arthur,

That did it.  Thanks much.
0
 

Author Comment

by:tdenny
ID: 7175313
Joe, Arthur,

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

839 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