Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2011
    Posts
    30

    Unanswered: IF, THEN and Enabling/Disabling Fields

    If i make a field "required" but set a VBA function to disable it under certain circumstances, does it become "not required" if those circumstances are met (in this case if Receipt is "no" as per the below snip of code)?


    Private Sub Receipt_AfterUpdate()
    'this is to show fields when a receipt is made

    Select Case Me.receipt.Value

    Case "1"
    Me.Receipt_Date.Visible = False
    Me.Receipt_Date.Enabled = False
    Me.Receipt_Date.Value = ""

  2. #2
    Join Date
    Jan 2012
    Posts
    97
    Do you mean you have set the required property of a field in a table to yes? As a data entry form simply acts as a user interface allowing users to enter data into your table it must still meet the property conditions set for fields in that table.

    In other words simply disabling the control that is bound to a required field will have no influence on the fact that that is still a required field and you should receive an error message when trying to save the record.

    Going by the information that you have provided this field should not have its required property set to yes. If you only require the user to enter data when certain conditions are met then you need to enforce this entry using logic elsewhere. A guess at a solution would be to make the following change to your code below and then add the following code in the BeforeUpdate event of the Receipt_Date field...

    Code:
    Private Sub Receipt_AfterUpdate()
    'this is to show fields when a receipt is made
    
    Select Case Me.receipt.Value
    
    Case "1"
    Me.Receipt_Date.Visible = False
    Me.Receipt_Date.Enabled = False
    Me.Receipt_Date.Value = ""
    Me.Receipt_Date.SetFocus 'Moves the focus straight to the field
    Case Else
    
    Private Sub Receipt_Date_BeforeUpdate(Cancel As Integer)
    If IsNull(Me.Receipt_Date) Then
    MsgBox ("Data is required in this field.")
    Cancel = True
    End If
    Hope this helps,

    Dave.

    _____________

    Access 2000 User

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •