Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2004
    Posts
    4

    Question Unanswered: Making fields dependant on other fields

    I'm using access 2002. I have three fields that are check boxes. I want several other fields to be required IF any of the check boxes are checked. Anybody know how I can do this? Thanks for any help

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Where do you want it done at???? It can't happen at the record level ... This is trivial to do in code ...
    Back to Access ... ADO is not the way to go for speed ...

  3. #3
    Join Date
    Oct 2004
    Posts
    4
    Quote Originally Posted by M Owen
    Where do you want it done at???? It can't happen at the record level ... This is trivial to do in code ...
    Sorry, that might help to let you know. I want it done on a data entry from if possible. I'm completely new to access so I don't know if I'm trying to do something that can't be done.

  4. #4
    Join Date
    Feb 2004
    Posts
    533
    Quote Originally Posted by Flyback
    I want several other fields to be required IF any of the check boxes are checked. Anybody know how I can do this? Thanks for any help
    This example uses the BeforeUpdate Event to check the text fields for a Null or Empty value. One thing I've done here which is optional for your problem is dimensioned a variable for the array at the module level and used it in the Sub setNames as well as the before update sub. Sub setNames enables or disables the textboxes as named in the array when the checkbox is clicked.

    This code would go in the code module of the form which opens when you select the Before_update event (or any event action of the form) on the Event Tab of the Form Properties window for the form your working with.

    Code:
    Option Compare Database
    
    Dim arryTB As Variant
    
    Sub setNames()
    ' put the names of the Required text fields
    ' Into an array.
        arryTB = Array("Text0", "Text2", "Text4")
    End Sub
    
    Private Sub Check6_Click()
    Dim bLockTxt As Boolean
    
    bLockTxt = False
    
    ' Make Var true to enable txt boxes
    If Me!Check6 = -1 Then
        bLockTxt = True
    End If
    
    If IsEmpty(arryTB) Then
        Call setNames
    End If
    
    ' Loop through text fields and Lock if Not Checked
    For i = 0 To UBound(arryTB)
        Me.Controls(arryTB(i)).Enabled = bLockTxt
    Next
    
    End Sub
    
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    Dim strTBname As String
    
    If IsEmpty(arryTB) Then
        Call setNames
    End If
    
    If Me!Check6 = -1 Then
        For i = 0 To UBound(arryTB)
            strTBname = arryTB(i)
            If IsNull(Me.Controls(strTBname)) Or Trim(Me.Controls(strTBname)) = "" Then
                MsgBox "You must fill in all Required Fields before updating the record."
                Cancel = True
                Exit Sub
            End If
        Next
    End If
    
    End Sub
    .
    Last edited by savbill; 10-11-04 at 17:25.
    ~

    Bill

  5. #5
    Join Date
    Oct 2004
    Posts
    4
    Thank you. Haven't had a chance to try it but I'm sure that'll work fine. If I've got any problems I'll be back. Thanks again man.

  6. #6
    Join Date
    Oct 2004
    Posts
    4
    Hey Bill, that worked well after some minor modification. I wanted to thank you GREATLY for your response. I really appreciate the help. Have a great weekend.

Posting Permissions

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