开发者

Permanently affect ms-access control properties using VBA

I have a fairly large Access application in QA. I've gotten a few issues like "some lables are bolded some aren't" which is not surprising given the way this app evolved. I'd like to write some code that runs once and sets control properties, as opposed to code that runs when the form opens to set each control's properties. I can do the latter but never really thought about the former until today. There are just so many lables on so many forms that I'd like to write a function that cycles through all my controls, set's the Font Weight for labels and saves that as the value for that control.

I'm fine with cycling through the controls, finding lables, but actually setting the property and saving it forever, versus doing in on some triggered event is stumping me. Anyone done this?

Than开发者_C百科ks in advance for your help!


I did this partly off-the-cuff so you may need to tweak it. Just close all your forms and run this procedure.

Be forewarned: this will set ALL of your labels to bold. Most fonts get wider when they are bolded, so you may need to tweak your form layouts after you do this. I'd highly recommend backing up the .mdb before you try this.

Sub SetFormProperties()
Dim ao As AccessObject, Frm As Form, Ctl As Control

    For Each ao In CurrentProject.AllForms
        If ao.IsLoaded Then
            Debug.Print ao.Name; " skipped...form was already loaded"
        Else
            DoCmd.OpenForm ao.Name, acDesign
            Set Frm = Forms(ao.Name)

            '-------------------'
            'Set properties here'
            For Each Ctl In Frm.Controls
                If Ctl.ControlType = acLabel Then
                    Ctl.FontWeight = 700
                    '---OR---'
                    Ctl.FontBold = True
                End If
            Next Ctl
            '-------------------'

            DoCmd.Close acForm, Frm.Name, acSaveYes
        End If
    Next ao
End Sub 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜