Microsoft Office Tutorials and References
In Depth Information
Changing Form Controls with VBA
Me.CCAuthorization.Enabled = False
Me.ExpireLabel.Visible = False
‘Now selectively show and enable controls,
‘and fill the Paid field, based on the
‘contents of the Payment Method control
Select Case Me.[Payment Method].Value
‘If selection is Cash...
Case “Cash”
Me.Paid.Value = True
‘If selection is Check...
Case “Check”
Me.CheckNo.Enabled = True
Me.Paid.Value = True
‘Move cursor to CheckNo control
DoCmd.GoToControl “CheckNo”
‘If selection is Credit Card...
Case “Credit Card”
Me.CCType.Enabled = True
Me.CCNumber.Enabled = True
Me.CCExpireMonth.Enabled = True
Me.CCExpireYear.Enabled = True
Me.CCAuthorization.Enabled = True
Me.ExpireLabel.Visible = True
Me.Paid.Value = True
‘Move cursor to CCType control
DoCmd.GoToControl “CCType”
‘If selection is Purchase Order...
Case “Purchase Order”
Me.PONumber.Enabled = True
Me.Paid.Value = False
‘Move cursor to PONumber control
DoCmd.GoToControl “PONumber”
Chapter 4
End Select
End Sub
The code and comments should be fairly easy to read. For starters, the sub
procedure name, Payment_Method_AfterUpdate(), tells you that this
code executes after a user makes a selection from the Payment Method
control and Access accepts that change.
The first lines below the Sub statement disable most controls and hide the
expiration label, just so that you know the status of each control before the
Select Case statement executes.
Search JabSto ::

Custom Search