Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Format Specific Columns in a list box (Access 2000)

Posted on 2003-12-02
4
Medium Priority
?
657 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
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
wsteegmans earned 500 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 500 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
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…
Suggested Courses

926 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