Solved

Error Compiling a function

Posted on 2002-07-24
8
1,449 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 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
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…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

707 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