Results 1 to 5 of 5
  1. #1
    albzn is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Aug 2015
    Posts
    12

    Check other fields when checking a checkobox

    Hi,

    Bear with me with my English, I hope you guys understand what I mean.

    I would like a checkbox on my access-form which, when ticked check some other fields on the form if they are filled or not.
    If not all the other fields are filled I would like some sort of window to say that not all fields are filled in.



    Also, if it's possible, I would like the fields to be locked afterwards (if all were filled). So no changes can be made afterwards.

    Please help, I have no clue where to start.

  2. #2
    knarfreppep is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Feb 2015
    Location
    Adelaide, Australia
    Posts
    106
    Quote Originally Posted by albzn View Post
    Hi,

    Bear with me with my English, I hope you guys understand what I mean.

    I would like a checkbox on my access-form which, when ticked check some other fields on the form if they are filled or not.
    If not all the other fields are filled I would like some sort of window to say that not all fields are filled in.

    Also, if it's possible, I would like the fields to be locked afterwards (if all were filled). So no changes can be made afterwards.

    Please help, I have no clue where to start.

    You may not need a checkbox.

    Create a text box: Name: txtCheckForMissingInformation, Enabled: False, Locked: True, RecordSource: =IIF(IsNull(txt1) Or IsNull(txt2) Or IsNull(txt3),"Information is missing.","")

    Then, in the form's BeforeUpdate event -
    If Len(txtCheckForMissingInformation) <> 0 Then
    MsgBox "Can't change completed information."
    Cancel = True
    End If

    I make no comment on whether what you're trying to do is a good idea.

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I use something similar to the following. The following code depends on the Tag property of controls. In this example, I include the text 'Required' in the Tag property of each control I want to validate.
    Code:
    Dim ctl As Control
    
        For Each ctl In Me.Controls
    
            If InStr(ctl.Tag, "Required") <> 0 Then
            ctl.BackColor = 16777215
                If IsNull(ctl.Value) Then   'You will also want to check for things like values of 0 or "" or .etc using additional code
                    ctl.BackColor = 65535
                    'Add some code to revert your checkbox control to not checked
                    'Me.CheckBoxName.Value = 0
                RequiredFields = True
                Else    'Go ahead and disable
                    ctl.Enabled = False
                End If  'IsNull
            End If  'Required
            
        Next ctl

  4. #4
    knarfreppep is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Feb 2015
    Location
    Adelaide, Australia
    Posts
    106
    Quote Originally Posted by ItsMe View Post
    I use something similar to the following. The following code depends on the Tag property of controls. In this example, I include the text 'Required' in the Tag property of each control I want to validate.
    Code:
    Dim ctl As Control
    
        For Each ctl In Me.Controls
    
            If InStr(ctl.Tag, "Required") <> 0 Then
            ctl.BackColor = 16777215
                If IsNull(ctl.Value) Then   'You will also want to check for things like values of 0 or "" or .etc using additional code
                    ctl.BackColor = 65535
                    'Add some code to revert your checkbox control to not checked
                    'Me.CheckBoxName.Value = 0
                RequiredFields = True
                Else    'Go ahead and disable
                    ctl.Enabled = False
                End If  'IsNull
            End If  'Required
            
        Next ctl
    I do something similar -

    For Each ctlControl In Controls
    If ctlControl.ControlType = acTextBox Or ctlControl.ControlType = acComboBox Then
    If Len(Nz(ctlControl.Value, "")) = 0 And Len(ctlControl.Tag) > 1 Then
    MsgBox "Please enter " & ctlControl.Tag
    ctlControl.SetFocus
    Cancel = True
    End If
    End If
    Next

    Testing Len() > 1 is faster than looking for 'Required' ... I don't use the Tag for any purpose other than the name of the data required if entering data is mandatory ... if one wants to maybe set it to, say, RYG (where R = Rquired Y = Yellow background if empty G = Green backgound if empty) then one only needs the faster If Not InStr(ctl.Tag, "R") = 0 Then

  5. #5
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    I think there is only one Access control that doesn't have a tag property, so I just redirect the error during the loop. If they ever create a control that doesn't have a tag and the code is re-used, it should still work. My approach checks all controls (not just text boxes and combo boxes) and adds the attached label caption to the list (not that I would be checking for "" or IsNull on all controls). Usually, the control name would be a poor choice to tell the user what is missing, so when doing this, I make sure the labels for tagged controls are attached. BTW, I used to use "Required" but discovered that it probably should be avoided. It's in this list: http://allenbrowne.com/AppIssueBadWord.html

    This is "air code" from memory, but should be close

    Code:
    Dim ctl As Control
    Dim strList as String, strMsg as String
    
    strMsg = "Please provide a value for:" & vbCrlf
    strList = ""
    On Error Resume Next
     For Each ctl In Me.Controls
       If ctl.Tag = "Reqd" Then
         If ctl = "" or IsNull(ctl) then strList = "  - "  & ctl.Controls(0).Caption & vbCrLf
       End If
    Next
    
    If strList <> "" Then 
      msgbox strMsg & strList
      Exit Sub
    End If
    On Error goto ErrHandler

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Cross Checking Two Fields for Duplicates
    By SmugglersBlues in forum Programming
    Replies: 11
    Last Post: 10-07-2015, 09:18 AM
  2. Checking Date Range in Multiple Fields
    By mac322n in forum Queries
    Replies: 1
    Last Post: 05-11-2015, 07:00 PM
  3. Replies: 0
    Last Post: 03-06-2012, 11:55 PM
  4. yes/no fields as check boxes
    By mejia.j88 in forum Reports
    Replies: 6
    Last Post: 01-30-2012, 10:01 AM
  5. Automaticaly checking a check box
    By brandonze in forum Forms
    Replies: 9
    Last Post: 07-07-2011, 08:58 AM

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
  •  
Other Forums: Microsoft Office Forums