473,399 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Why Am I Getting Runtime Error 3251?

I found some VBA code posted by ADezii on this site that will generate a list of users who are currently logged into my database. I pasted this code into the VBA window of a new blank form, following the instructions from the developer. The problem is I am getting a compile error whenever I run the code. I am using the Front End of an Access 2010 database. I also have access to the Back End as I have developed the DB myself. The code is listed as Private Function GenerateUserList() and is called from the Open Event in the form and is set to refresh every ten seconds.

What I have tried:
I tried pasting this code into a module and calling it in the form, but I the same line of code triggers an error. I researched and found similar posts, but not one that showed the same error I received. Any help is greatly appreciated!

Error Message:
Runtime error 3251. Object or provider is not capable of performing requested operation.

Code That Triggers Error:
Set rst = cnn.OpenSchema(Schema:=adSchemaProviderSpecific, SchemaID:=conUsers)

Original VBA Code:
The code that triggers the error when I compile is in blue, bold print.

Code:
Expand|Select|Wrap|Line Numbers
  1.  Private Function GenerateUserList()
  2. 'The User List Schema information requires this magic number. For anyone
  3. 'who may be interested, this number is called a GUID or Globally Unique
  4. 'Identifier - sorry for digressing
  5. Const conUsers = "{947bb102-5d43-11d1-bdbf-00c04fb92675}"
  6.  
  7. Dim cnn As ADODB.Connection, fld As ADODB.Field, strUser As String
  8. Dim rst As ADODB.Recordset, intUser As Integer, varValue As Variant
  9.  
  10. Set cnn = CurrentProject.Connection
  11. Set rst = cnn.OpenSchema(Schema:=adSchemaProviderSpecific, SchemaID:=conUsers)
  12.  
  13. 'Set List Box Heading
  14. strUser = "Computer;UserName;Connected?;Suspect?"
  15.  
  16. With rst    'fills Recordset (rst) with User List data
  17.   Do Until .EOF
  18.     intUser = intUser + 1
  19.       For Each fld In .Fields
  20.         varValue = fld.Value
  21.           'Some of the return values are Null-Terminated Strings, if
  22.           'so strip them off
  23.           If InStr(varValue, vbNullChar) > 0 Then
  24.             varValue = Left(varValue, InStr(varValue, vbNullChar) - 1)
  25.           End If
  26.           strUser = strUser & ";" & varValue
  27.       Next
  28.         .MoveNext
  29.   Loop
  30. End With
  31.  
  32. Me!txtTotalNumOfUsers = intUser        'Total # of Users
  33.  
  34. 'Set up List Box Parameters
  35. Me!lstUsers.ColumnCount = 4
  36. Me!lstUsers.RowSourceType = "Value List"
  37. Me!lstUsers.ColumnHeads = False
  38.   lstUsers.RowSource = strUser       'populate the List Box
  39.  
  40. 'Routine cleanup chores
  41. Set fld = Nothing
  42. Set rst = Nothing
  43. Set cnn = Nothing
  44.  End Function
  45.  
  46. Private Sub Form_Open(Cancel As Integer)
  47.   Call GenerateUserList
  48. End Sub
  49.  
  50.  Private Sub Form_Timer()
  51.   Call GenerateUserList
  52. End Sub 
Dec 22 '14 #1
2 3563
twinnyfo
3,653 Expert Mod 2GB
andigirlsc,

I use a slightly different version of this code:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. 'Set some Constants and Public Variables
  5. Private Const dbLockFile As String = "\\NetworkLocation\NetworkFolder\DatabaseName.laccdb"
  6.  
  7. Private Sub CurrentUsers()
  8. On Error GoTo EH
  9.     Dim strCurrentUsers As String
  10.     Dim strUserString   As String
  11.     Dim intFileNumber   As Integer
  12.     Dim LineofText      As String
  13.     Dim intPointer      As Integer
  14.     intFileNumber = FreeFile
  15.     If fIsFileDir(dbLockFile) Then
  16.         Open dbLockFile For Input As #intFileNumber
  17.         Me.txtLockFileContents = ""
  18.         strCurrentUsers = ""
  19.         strUserString = ""
  20.         Do While Not EOF(intFileNumber)
  21.             ' Read each line of the text file into a single string variable.
  22.             Line Input #intFileNumber, LineofText
  23.             While Len(LineofText) > 0 And Len(LineofText) >= 62
  24.                 intPointer = 1
  25.                 Do While Mid(LineofText, intPointer, 1) <> " "
  26.                     intPointer = intPointer + 1
  27.                 Loop
  28.                 strUserString = Left(LineofText, intPointer - 1)
  29.                 strCurrentUsers = IIf(Len(strCurrentUsers) = 0, strUserString, _
  30.                     strCurrentUsers & vbCrLf & strUserString)
  31.                 LineofText = Right(LineofText, Nz(Len(LineofText) - 62, 0))
  32.             Wend
  33.         Loop
  34.         Close #intFileNumber
  35.         Me.txtLockFileContents = strCurrentUsers
  36.     Else
  37.         Me.txtLockFileContents = "No Current Users"
  38.     End If
  39.     Exit Sub
  40. EH:
  41.     MsgBox "There was an error finding all Current Users.  " & _
  42.         "Please contact your Database Administrator.", vbCritical, "Error!"
  43.     Exit Sub
  44. End Sub
  45. Private Function fIsFileDir(strPath As String, Optional lngType As Long) As Integer
  46. On Error Resume Next
  47.     'Check to see if file exists
  48.     fIsFileDir = Len(Dir(strPath, lngType)) > 0
  49. End Function
This will return the Computer Name of the user that is logged into the DB. With another table containing Computer Names and Users, you can easily find the person who is logged in.

Hope this hepps!
Feb 25 '15 #2
Hi I am facing the same problem . Can you please help me out

Thanks

@twinnyfo I tried the code shared by you but its not returning anything

Expand|Select|Wrap|Line Numbers
  1.  Sub CurrentUsers()
  2.             Dim strCurrentUsers As String
  3.             Dim strUserString   As String
  4.             Dim intFileNumber   As Integer
  5.             Dim LineofText      As String
  6.             Dim intPointer      As Integer
  7.             Dim dbLockFile As String
  8.             intFileNumber = FreeFile
  9.             dbLockFile = CurrentProject.Path & "\" & CurrentDb.Name
  10.             Open dbLockFile For Input As #intFileNumber
  11.  
  12.             strCurrentUsers = ""
  13.             strUserString = ""
  14.             Do While Not EOF(intFileNumber)
  15.                 ' Read each line of the text file into a single string variable.
  16.                 Line Input #intFileNumber, LineofText
  17.                 While Len(LineofText) > 0 And Len(LineofText) >= 62
  18.                     intPointer = 1
  19.                     Do While Mid(LineofText, intPointer, 1) <> " "
  20.                         intPointer = intPointer + 1
  21.                     Loop
  22.                     strUserString = Left(LineofText, intPointer - 1)
  23.                     strCurrentUsers = IIf(Len(strCurrentUsers) = 0, strUserString, _
  24.                         strCurrentUsers & vbCrLf & strUserString)
  25.                     LineofText = Right(LineofText, Nz(Len(LineofText) - 62, 0))
  26.                 Wend
  27.             Loop
  28.             Close #intFileNumber
  29.             MsgBox strCurrentUsers
  30.     End Sub
code i am trying to use
Apr 2 '15 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Bill Patel | last post by:
I am getting Runtime error on line 50. Please Help. Thank You Bill 1 <%@ Page Language="VB" %> 2 <%@ import Namespace="System.Data" %> 3 <%@ import Namespace="System.Data.SqlClient"...
4
by: Pat | last post by:
In my Web.config i have :- <customErrors mode="On" defaultRedirect="genericerror.htm"> <error statusCode="404" redirect="pagenotfound.aspx"/> </customErrors to get page not found error but...
1
by: ydprasad | last post by:
I am trying to convert the code that was written in VB using DAO to ADO. But when i tried to do following getting an error '3251'. *************code************************** Dim cn As New...
6
by: akoymakoy | last post by:
Run time error 3251 Current Recordset does not support updating, this may be a limitation of the provider, or of the selected Locktype This is my simple program that will split the entries that...
7
by: ruvi | last post by:
I am getting runtime error 3021 - Either EOF or BOF is true or the current record has been deleted..... I have 2 combo boxes in a form- One for the client and the other for the project. When the...
1
by: Lauren Dobson | last post by:
This database was working days ago, outputting a vocabulary list into a word document. Any idea why I'm getting runtime error 3010? I just switched from Windows XP to Windows 7 but I'm still using...
1
by: creation | last post by:
$b= 1; while($b) { $a = <>; if($a eq 42) break; else { print $a; }
1
by: mishika | last post by:
Q: getting runtime error 52 bas file name or number D:Public Function gf_ChkMkDir(iDirPath As String, iDirName As String) As Boolean Dim MyPath As String gf_ChkMkDir = False MyPath =...
8
by: Vasago | last post by:
Bookings ID is number ID is autonumber Error says: Run-Time error '2471': The expression you entered as a query parameter produced this error: '' If DCount("", "Access Click log", " = " &...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.