Solved

Format Specific Columns in a list box (Access 2000)

Posted on 2003-12-02
4
639 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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…

622 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