Advertisement

11.07.2007 at 01:24PM PST, ID: 22946017
[x]
Attachment Details

help fix teh function plz!

Asked by Moother in Microsoft Access Database

Tags: column, prp, tabledef

these two functions adjust column widths of a table to "fit to"... i use quote marks because it seems to take the width of the widest cell ON THE SCREEN and set the column width to that in twips.

is it possible to adjust the functions so that it finds the WIDEST value of the WHOLE column? or will that take too long?

thanks for your input.

Public Function FixColumnWidthsOfTable(stName As String)
   
    Dim db As Database
    Dim tdf As TableDef
    Dim fld As DAO.Field
    Dim frm As Form
    Dim ictl As Integer
    Dim ctl As Control
   
    Set db = CurrentDb
    Set tdf = db.TableDefs(stName)
    DoCmd.OpenTable stName, acViewNormal
    Set frm = Screen.ActiveDatasheet
    For ictl = 0 To frm.Controls.Count - 1
     Set ctl = frm.Controls(ictl)
     ctl.ColumnWidth = -2
     Call SetDAOFieldProperty(tdf.Fields(ictl), "ColumnWidth", ctl.ColumnWidth, dbInteger)
    Next ictl
    DoCmd.Save acTable, stName
End Function

Private Sub SetDAOFieldProperty(fld As DAO.Field, stName As String, vValue As Variant, lType As Long)
   
    Dim prp As DAO.Property
   
    For Each prp In fld.Properties
        If StrComp(prp.name, stName, vbBinaryCompare) = 0 Then
            prp.value = vValue
            Exit For
            Debug.Print fld.name
        End If
        Set prp = Nothing
    Next prp
   
    If prp Is Nothing Then
        Set prp = fld.CreateProperty(stName, lType, vValue)
        fld.Properties.Append prp
    End If
End SubStart Free Trial
 
Loading Advertisement...
 
[+][-]11.07.2007 at 01:48PM PST, ID: 20236775

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Access Database
Tags: column, prp, tabledef
Sign Up Now!
Solution Provided By: RDWaibel
Participating Experts: 1
Solution Grade: A
 
 
[+][-]11.07.2007 at 02:00PM PST, ID: 20236902

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_EXPERT_20070906