[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Error Compiling a function

Posted on 2002-07-24
8
Medium Priority
?
1,539 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
[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
  • 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 400 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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

656 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