Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Format Specific Columns in a list box (Access 2000)

Posted on 2003-12-02
4
Medium Priority
?
648 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 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

722 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