Results 1 to 9 of 9
  1. #1
    Star Lounger
    Join Date
    Mar 2003
    Location
    Summerville, South Carolina, USA
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Calling the Immediate Window (Access 2000)

    I have created a public module that when I type in the immmediate window, it shows me all the computer names that are currently logged in a database. The function is ?getusers() and it returns a list of 1 to 20 names. I would like to call this function from a form or report so that my non-technical person would just click a button and be able to view names of the current users. Is there a way to call this function on a report or form? Any help would be appreciated. Thanks.

  2. #2
    Lounger
    Join Date
    Mar 2002
    Location
    St Albans, Hertfordshire, England
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calling the Immediate Window (Access 2000)

    Create an unbound text box on the form, and in your function, instead of debug.print, just change it to forms!form!txtControl = forms!form!txtControl & vbcrlf & strUser (or whatever your output string is).

    Thanks

  3. #3
    Star Lounger
    Join Date
    Mar 2003
    Location
    Summerville, South Carolina, USA
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calling the Immediate Window (Access 2000)

    Thanks for the info. I am rather new at this VB stuff. Can you look at the below function and show me what the syntax would be? My form name is frmUser with my text box named txtUser. I don't understand what the output string would be or what vbcrlf is. Thanks.

    Public Function getusers(Optional StrDbPath As String)

    ReDim lpszUserBuffer(100) As String
    Dim intLooper As Integer
    Dim Cusers As Long
    Dim strMsgBox As String
    Dim strDB As String

    On Error GoTo Err_GetUsers


    ' Check to see if a database path was passed
    ' to the function. If the argument was not used,
    ' assume that we're to investigate the .ldb
    ' of the current database.
    StrDbPath = ("x:ssdsystem support database.mdb")

    ' Set Cusers to the number of computers currently connected
    ' to the database. Insert computer information into the
    ' lpszUserBuffer array.

    ' Arguments of LdbUser_Get Users:
    ' 1 = All users who have logged in since the LDB file was
    ' created
    ' 2 = Only users who are currently logged in
    ' 4 = Only users who are causing the database file to be
    ' corrupted
    ' 8 = Just return the count of users

    Cusers = LDBUser_GetUsers(lpszUserBuffer(), StrDbPath, 2)

    ' Print possible errors returned by the function.
    Select Case Cusers
    Case -1
    strMsgBox = "Can't open the LDB file"
    Case -2
    strMsgBox = "No user connected"
    Case -3
    strMsgBox = "Can't Create an Array"
    Case -4
    strMsgBox = "Can't redimension array"
    Case -5
    strMsgBox = "Invalid argument passed"
    Case -6
    strMsgBox = "Memory allocation error"
    Case -7
    strMsgBox = "Bad index"
    Case -8
    strMsgBox = "Out of memory"
    Case -9
    strMsgBox = "Invalid Argument"
    Case -10
    strMsgBox = "LDB is suspected as corrupted"
    Case -11
    strMsgBox = "Invalid argument"
    Case -12
    strMsgBox = "Unable to read MDB file"
    Case -13
    strMsgBox = "Can't open the MDB file"
    Case -14
    strMsgBox = "Can't find the LDB file"
    End Select

    If Not IsEmpty(strMsgBox) And strMsgBox <> "" Then
    MsgBox strMsgBox, vbCritical, "Error"
    Exit Function
    End If

    ' Print computer names to Debug window.
    For intLooper = 0 To Cusers - 1
    Debug.Print "User"; intLooper + 1; ":"; _
    lpszUserBuffer(intLooper)
    Next

    Exit_GetUsers:
    Exit Function
    Err_GetUsers:
    MsgBox Err.Description
    Resume Exit_GetUsers

    End Function

  4. #4
    Lounger
    Join Date
    Mar 2002
    Location
    St Albans, Hertfordshire, England
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calling the Immediate Window (Access 2000)

    Where your code reads

    ------------------------------------------------
    ' Print computer names to Debug window.
    For intLooper = 0 To Cusers - 1
    Debug.Print "User"; intLooper + 1; ":"; _
    lpszUserBuffer(intLooper)
    Next
    ------------------------------------------------

    change this to:

    ------------------------------------------------
    ' Print computer names to Debug window.
    For intLooper = 0 To Cusers - 1
    forms!frmUser!txtUser = forms!frmUser!txtUser & vbcrlf & "User"; intLooper + 1; ":"; _ 'vbcrlf = Carriage Return Line Feed
    lpszUserBuffer(intLooper)
    Next
    ------------------------------------------------

    This will then direct the output of the function to the text box, adding a new line for each entry

    There are other ways of doing this (i.e. using a listbox, and adding a newitem to the listbox for each user), but these get more complicated - if you are happy for a simple approach, then this is it.

    Out of interest, this appears to be a very useful function - would you be offended if I asked you to post the LDBUser_GetUsers function as well <img src=/S/please.gif border=0 alt=please width=31 height=23> - I could really make do with something like this - the routne I use is extremely complicated <img src=/S/blush.gif border=0 alt=blush width=15 height=15>!

    Kind regards

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Calling the Immediate Window (Access 2000)

    vbCrLf is a Visual Basic constant; it represents a string that is equivalent to a Carriage Return/Line Feed, in other words, to the result of pressing Enter in a text.

    Replace

    For intLooper = 0 To Cusers - 1
    Debug.Print "User"; intLooper + 1; ":"; _
    lpszUserBuffer(intLooper)
    Next

    by

    Dim strResult As String
    For intLooper = 0 To Cusers - 1
    strResult = strResult & "User" & intLooper + 1 & ": " lpszUserBuffer(intLooper)
    Next
    Me.txtUser =strResult

    Make the text box high enough to view a few lines at a time.

  6. #6
    Star Lounger
    Join Date
    Mar 2003
    Location
    Summerville, South Carolina, USA
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calling the Immediate Window (Access 2000)

    Just so I have this right. My function is in a public module. Do I need to create this on form module instead? Sorry for being so dumb. Lke I said, I am new to this.

    Thanks

    Here is the LDBUser_Getuser function.
    Option Compare Database
    Declare Function LDBUser_GetUsers Lib "MSLDBUSR.DLL" _
    (lpszUserBuffer() As String, ByVal lpszFilename As String, _
    ByVal nOptions As Long) As Integer

  7. #7
    Lounger
    Join Date
    Mar 2002
    Location
    St Albans, Hertfordshire, England
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calling the Immediate Window (Access 2000)

    You can call the public function from within a form

    Turn off the Tools Wizard (on the toolbox - looks like a wand) - then add a new command button onto the frmUsers

    Set the name of the new button to cmdGetUsers

    In the properties box, goto events, and then select 'On Click', using the '...' button that appears to the far right of the line - select the code option

    You are then in VBA, with the cmdGetUsers_OnClick () event

    Just add the line GetUsers() - this will then run the function - if you comment out the line StrDbPath = ("x:ssdsystem support database.mdb") from the module, this will then run for the active database

    Hope that helps

    Thanks for the additional code - I don't have the necessary DLL required to run it, so I'll have to stick to my own code.

    Kind regards

  8. #8
    Star Lounger
    Join Date
    Mar 2003
    Location
    Summerville, South Carolina, USA
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calling the Immediate Window (Access 2000)

    Perfect. That all of you that helped. This gets me out of managing who is in the database and who we need to kick out.
    Thanks

  9. #9
    Star Lounger
    Join Date
    Mar 2003
    Location
    Summerville, South Carolina, USA
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calling the Immediate Window (Access 2000)

    Hey Chris. I am not sure if you have access to it, but the DLL file can be downloaded from Microsoft's knowledge base. The article number is <!mskb=176670>Microsoft Knowledge Base Article 176670<!/mskb>. The last third of the page has an exe file named Jetutils.exe. Extract the file and save it in your program files/microsoft/microsoft office/office file.

    hope that helps.

    (Edited by HansV to provide link to MSKB article)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •