Solved

Format Specific Columns in a list box (Access 2000)

Posted on 2003-12-02
4
634 Views
Last Modified: 2006-11-17
Hi,

I'm using a rowsourcetype callback function to format specific columns in a list box, however my boss says it's too slow!

Does anyone know an alternative method, e.g. using APIs ?

Here's my code ... maybe somone has a suggestion ...

Function GenListBox(ctl As Access.Control, ID As Variant, varRow As Variant, varCol As Variant, varCode As Variant) As Variant
'---------------------------------------------------------------------------------------------------------------------------------------------------------------------
'GenListBox
'
'Populates a listbox from the SQL statement found in gstrSQL
'Currency formatting is determined by the current project setting
'
'Author Julian Greene
'---------------------------------------------------------------------------------------------------------------------------------------------------------------------

Dim cnnSQL As ADODB.Connection
Static rstSource As ADODB.Recordset
Dim varReturn As Variant

Select Case varCode
       
        Case acLBInitialize                ' Initialize.
        Set cnnSQL = CurrentProject.Connection
        Set rstSource = New ADODB.Recordset
        rstSource.Open gstrSQL, cnnSQL, adOpenStatic, adLockReadOnly
        varReturn = True
           
        Case acLBOpen                        ' Open.
            ' Generate unique ID for control.
            varReturn = Timer
        Case acLBGetRowCount            ' Get number of rows. (add 1 this is supposed to give the field names as well)
        varReturn = rstSource.RecordCount + 1
       
        Case acLBGetColumnCount    ' Get number of columns.
        varReturn = rstSource.Fields.Count
           
        Case acLBGetColumnWidth    ' Column width.
            ' -1 forces use of default width.
            varReturn = -1
       
        Case acLBGetValue                    ' Get data.
            If varRow = 0 Then
                varReturn = rstSource.Fields(varCol).Name
            Else
                rstSource.AbsolutePosition = varRow
                varReturn = rstSource(varCol)
            End If
       
        Case acLBGetFormat                   'Format currency values
            If rstSource.Fields(varCol).type = adCurrency Then
                varReturn = CCFormat
            Else
                varReturn = -1
            End If
           
           
        Case acLBEnd                        ' End.
            Set rstSource = Nothing
    End Select
    GenListBox = varReturn

End Function


Public Function CCFormat() As String
'-----------------------------------------------------------------------------------------------------------------------------------------
'CCFormat
'
'Returns the current currency format, as determined by the value of gstrCompany
'
'Author Julian Greene
'------------------------------------------------------------------------------------------------------------------------------------------
Select Case gstrCompany
Case Is = "HLSP", "IHSD"
    CCFormat = "£#,##0.00;-£#,##0.00;"
Case Is = "HLSP Spain"
    CCFormat = "€#,##0.00;-€#,##0.00;"
Case Is = "HLSP BDS"
    CCFormat = "Tk#,##0.00;-Tk#,##0.00;"
End Select

End Function

0
Comment
Question by:Natchiket
[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
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
wsteegmans earned 125 total points
ID: 9856703
Try to format your Currency Fields in your SQL-Statement (gstrSQL).
So, change your List Box properties to
- RowSource Type = Table/Query
- Control Source = Your naw SQL-Statement with formats for your currency fields

You're processing it step by step, row by row. It will go much faster when Access can do it (fetching the data) ...

Check also if your query isn't too slow. Just try this:
        Set cnnSQL = CurrentProject.Connection
        Set rstSource = New ADODB.Recordset
        rstSource.Open gstrSQL, cnnSQL, adOpenStatic, adLockReadOnly
        rstSource.MoveLast
        MsgBox "All records are fetched!"

If this takes a while, fetching your data takes a while ... Change your query, or add some good indexes to your tables ...

Regards!
0
 
LVL 34

Assisted Solution

by:Mike Eghtebas
Mike Eghtebas earned 125 total points
ID: 9856715
I wonder if this would do the job?
        .
        .
        Case acLBGetValue                    ' Get data.
            If varRow = 0 Then
                varReturn = rstSource.Fields(varCol).Name
            Else
                rstSource.AbsolutePosition = varRow

                   Select Case CCFormat                
                   Case Is = "HLSP", "IHSD"
                       CCFormat = Format(rstSource(varCol),"£#,##0.00")
                   Case Is = "HLSP Spain"
                       CCFormat = Format(rstSource(varCol),"€#,##0.00")
                   Case Is = "HLSP BDS"
                       CCFormat = Format(rstSource(varCol),"Tk#,##0.00")
                   End Select
                   'varReturn = rstSource(varCol)
            End If
       
 '       Case acLBGetFormat                   'Format currency values
 '           If rstSource.Fields(varCol).type = adCurrency Then
 '               varReturn = CCFormat
 '           Else
 '               varReturn = -1
 '           End If
        .
        .

Mike
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 9856720
Oops...

                   Select Case CCFormat                
                   Case Is = "HLSP", "IHSD"
                       varReturn = Format(rstSource(varCol),"£#,##0.00")
                   Case Is = "HLSP Spain"
                       varReturn = Format(rstSource(varCol),"€#,##0.00")
                   Case Is = "HLSP BDS"
                       varReturn = Format(rstSource(varCol),"Tk#,##0.00")
                   End Select
0
 
LVL 17

Author Comment

by:Natchiket
ID: 9857043
Thanks,

Actually my boss now concedes that his underlying views, or at least the interaction between the SQL Server views and Access that is at fault.  He's decided to dump the views into tables and now all is sweetness and light.

Thanks for the help anyways, going to split the points equally
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

726 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