Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Cape Town, South Africa, South Africa
    Posts
    399
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Statusbar (Access 2000)

    Can someone help me with the code to access the Statusbar in Access. I'm doing an import and would like to show 10 Files of 20 imported

    Thanks

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

    Re: Statusbar (Access 2000)

    You can use SysCmd for this:

    Dim intCurrent As Integer
    Dim intTotal As Integer
    Dim strStatus As String

    intCurrent = 10
    intTotal = 20
    strStatus = intCurrent & " files of " & intTotal & " imported."
    SysCmd acSysCmdSetStatus, strStatus

    To clear the status bar:

    SysCmd acSysCmdClearStatus

  3. #3
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Cape Town, South Africa, South Africa
    Posts
    399
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Statusbar (Access 2000)

    Many thanks

    Mario

  4. #4
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Statusbar (Access 2000)

    Note that you can also use SysCmd to display a progress meter in the Status Bar while some performing a time-consuming task such as looping thru a recordset or running an import/export function. If interested, here is example:

    Option Compare Database
    Option Explicit

    Private Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)

    Sub TestSysCmdMeter(ByRef lngCount As Long)
    On Error GoTo Err_Handler

    Dim strMsg As String
    Dim n As Long
    ' lngCount = number of records being processed, files imported, etc

    ' Ensure Status Bar visible:
    SetOption "Show Status Bar", True

    For n = 1 To lngCount
    ' Results in: Error No 7952: You made an illegal function call:
    ' SysCmd acSysCmdSetStatus, "Importing file " & n & "..."
    ' SysCmd acSysCmdUpdateMeter, n
    ' Cannot SetStatus then UpdateMeter....
    ' Goofy workaround:
    ' Re-Initialize meter each loop:
    SysCmd acSysCmdInitMeter, "Importing file " & n & " of " & lngCount & "...", lngCount
    SysCmd acSysCmdUpdateMeter, n
    ' For demo purposes only - pause execution 1 second:
    Sleep 1000
    Next

    SysCmd acSysCmdSetStatus, "Ready"

    Exit_Sub:
    ' If error be sure to clear Status Bar:
    SysCmd acSysCmdClearStatus
    Exit Sub

    Err_Handler:
    Select Case Err.Number
    Case 0
    Resume Next
    Case Else
    strMsg = "Error No " & Err.Number & ": " & Err.Description
    MsgBox strMsg, vbExclamation, "ERROR MESSAGE"
    Debug.Print strMsg
    Resume Exit_Sub
    End Select
    End Sub

    As noted in commented-out code, you cannot use acSysCmdSetStatus to update text, then acSysCmdUpdateMeter to update progress meter; this results in Illegal Function Call error. The workaround is to re-initialize the meter each loop, as the acSysCmdInitMeter argument allows you to specify the status bar text in addition to maximum value of the meter (100 percent value). Above example uses Windows Sleep API function to pause execution for demo purposes only; in actual use you'd increment the meter by n for each record, file, etc being processed by your procedure.

    When you just want to display some text in Status Bar w/o progress meter, you can also use the Application Echo method. Example:

    Sub TestEchoMethod(ByRef fEchoOn As Boolean, ByRef strStatusBarText As String)
    On Error GoTo Err_Handler
    Dim strMsg As String

    ' Ensure Status Bar visible:
    SetOption "Show Status Bar", True

    ' Turn screen repainting on/off:
    Application.Echo fEchoOn, strStatusBarText
    ' Do stuff here
    strMsg = "Test message."
    MsgBox strMsg, vbInformation, strMsg

    Exit_Sub:
    ' Turn screen repainting on & reset Status Bar:
    Application.Echo True, "Ready"
    Exit Sub
    Err_Handler:
    Select Case Err.Number
    Case 0
    Resume Next
    Case Else
    strMsg = "Error No " & Err.Number & ": " & Err.Description
    MsgBox strMsg, vbExclamation, "ERROR MESSAGE"
    Resume Exit_Sub
    End Select

    End Sub

    Example of usage (repainting not turned off): TestEchoMethod True, "Test Status Bar Text"

    The Echo method turns screen repainting on and off. You don't have to turn off screen repainting to display text in Status Bar, specify True for first argument. For both SysCmd and Echo, it is highly recommended that you use error handling as shown to ensure Status Bar (and screen repainting if using Echo) are reset in event of unexpected error, or the Status Bar may get "stuck" with the text until Access is restarted.

    HTH

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Statusbar (Access 2000)

    Thanks from me too!

Posting Permissions

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