Solved

Format Specific Columns in a list box (Access 2000)

Posted on 2003-12-02
4
630 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 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 33

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 33

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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now