ACC2000: How to Use VBA to Set Default Control PropertiesID: Q200593
|
Advanced: Requires expert coding, interoperability, and multiuser skills.
This article shows you how to use Visual Basic for Applications to set
properties for default controls on forms and reports.
Microsoft provides programming examples for illustration only, without warranty
either expressed or implied, including, but not limited to, the implied warranties of
merchantability and/or fitness for a particular purpose. This article assumes that you
are familiar with the programming language being demonstrated and the tools used to
create and debug procedures. Microsoft support professionals can help explain the functionality
of a particular procedure, but they will not modify these examples to provide added
functionality or construct procedures to meet your specific needs. If you have limited
programming experience, you may want to contact a Microsoft Certified Solution Provider
or the Microsoft fee-based consulting line at (800) 936-5200. For more information about
Microsoft Certified Solution Providers, please see the following page on the World Wide Web:
http://www.microsoft.com/mcsp/For more information about the support options available from Microsoft, please see the following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/overview/overview.aspIn order to set properties for default controls, you must use the form's DefaultControl method. Note that, although you can use this method to set properties for default controls, not all of a control's properties are available as default properties.
Option Explicit
Sub SetDefaultProperties()
Dim frm As Form
Dim ctl As Control
Set frm = CreateForm()
Set ctl = frm.DefaultControl(acTextBox)
With ctl
' Add a label for new textboxes.
.AutoLabel = True
' Do not include a colon in labels for new textboxes.
.AddColon = False
' Align label text to the right for new textboxes.
.LabelAlign = 3
' Place labels for new textboxes 1/4 inch above
' and aligned to the left.
.LabelX = 1440 * .33
.LabelY = -1440 * .25
' Center text in new textboxes.
.TextAlign = 2
End With
DoCmd.SelectObject acForm, frm.Name, False
DoCmd.Restore
End Sub
SetDefaultPropertiesNote that a new, blank form opens in Design view.
For more information about using Visual Basic for Applications to set the properties of default controls, click Microsoft Access Help on the
Help menu, type "DefaultControl method" in the Office Assistant or the Answer Wizard,
and then click Search to view the topics returned.
Additional query words:
Keywords : kbprg kbdta FmrHowto
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: July 6, 1999