UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Error opening a form with VBA coding    
 
   
khkeener
post Feb 9 2008, 01:00 PM
Post #1

UtterAccess Guru
Posts: 634
From: Texas, then Kansas, now Michigan



I am attempting to add coding to a form that will record the user's name and start time and end time when they log on to a database. I am using the code found in the Code Archive, found here .
This code is used in the "On Load" event:
CODE
Private Sub Form_Load()
'When the database opens these are the steps it takes to each user EVERY time they log in

    Me.txtUserName = fOSUserName 'retrieves the user name
    LogIN 'Function that creates a login and time stamp when the user logs in. This function will also
          'kick a user out of the database if they user is not registered in the employee table or has been deactivated

  
    Dim rs As ADODB.Recordset
    Dim cmd As ADODB.Command
    
    Set rs = New ADODB.Recordset
    Set cmd = New ADODB.Command
    
    
        cmd.ActiveConnection = CurrentProject.Connection
        cmd.CommandText = "SELECT AccessLevel FROM tblEmployee " _
                        & "WHERE UserName = '" & Me.txtUserName & "'"
        cmd.Execute
        rs.Open cmd, , adOpenKeyset, adLockOptimistic

Set rs = Nothing
Set cmd = Nothing
End Sub
and works well in the example from the code archive.

However, when I add it to my form, I get the "Compile Error: User-defined type not defined". The field that is highlighted when this pops up is rs as ADODB.Recordset

Unfortunately, I have absolutely no idea what this means or how to fix it.

Any ideas?

Kevin
Go to the top of the page
 
+
theDBguy
post Feb 9 2008, 02:01 PM
Post #2

Access Wiki and Forums Moderator
Posts: 47,901
From: SoCal, USA



It seems that you may be missing a reference to the ADO library. While in the code window, click on Tools>References and make sure that "Microsoft ActiveX Data Objext x.x Library" is checked. HTH
Go to the top of the page
 
+
khkeener
post Feb 9 2008, 02:31 PM
Post #3

UtterAccess Guru
Posts: 634
From: Texas, then Kansas, now Michigan



DBGuy, thank you. That was the problem. I went back to the example from the Code Archive and looked up what the version was and then selected the same one for my database and that fixed it.

Thanks again for helping me with this!!

Kevin
Go to the top of the page
 
+
theDBguy
post Feb 9 2008, 05:16 PM
Post #4

Access Wiki and Forums Moderator
Posts: 47,901
From: SoCal, USA



You're very welcome. Glad you were able to fix it. Good luck with your project.
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 18th May 2013 - 05:32 AM