Solved

Error Compiling a function

Posted on 2002-07-24
8
1,386 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

809 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