required info / checkbox

bionicman

Registered User.
Local time
Today, 05:43
Joined
Jul 22, 2003
Messages
145
Hello, I found this code elsewhere on this board and was able to manipulate it for my db, so it pops up a message box with what fields still need information. my problem is that i want this to happen when i click a checkbox. my checkbox already disables all of the other fields though, so that you cannot update the information.

is there a way to change this so it will only disable the boxes if the information is entered, and not disable them if they are blank?

example:
I leave field1 blank, when i click the checkbox it will say "please fill in field1" then lets me go back to change it INSTEAD of making it diabled?

Thank you,
BionicMan


Here is my code (please bear with me, i know VERY little about coding)


Code:
Private Sub Form_Current()
If Resolved = True Then
    Comment.Enabled = False
    Resolution.Enabled = False
    Appointment_Date.Enabled = False
    Appointment_Time.Enabled = False
    Comment_Date.Enabled = False
    First_Name.Enabled = False
    Last_Name.Enabled = False
    Medicaid__.Enabled = False
    Trip__.Enabled = False
Else
    Comment.Enabled = True
    Resolution.Enabled = True
    Appointment_Date.Enabled = True
    Appointment_Time.Enabled = True
    Comment_Date.Enabled = True
    First_Name.Enabled = True
    Last_Name.Enabled = True
    Medicaid__.Enabled = True
    Trip__.Enabled = True
End If

If IsNull([Resolution]) = True Then
    Resolved.Enabled = False
Else
    Resolved.Enabled = True
End If
End Sub
Private Sub Resolved_Click()
If Resolved = True Then
    Comment.Enabled = False
    Resolution.Enabled = False
    Appointment_Date.Enabled = False
    Appointment_Time.Enabled = False
    Comment_Date.Enabled = False
    First_Name.Enabled = False
    Last_Name.Enabled = False
    Medicaid__.Enabled = False
    Trip__.Enabled = False
Else
    Comment.Enabled = True
    Resolution.Enabled = True
    Appointment_Date.Enabled = True
    Appointment_Time.Enabled = True
    Comment_Date.Enabled = True
    First_Name.Enabled = True
    Last_Name.Enabled = True
    Medicaid__.Enabled = True
    Trip__.Enabled = True
End If

If Resolved.Value = True Then
    Dim strFields As String
    strFields = checkFields
    If strFields <> "" Then
        MsgBox "Please fill in the following fields:" & vbNewLine & vbNewLine & strFields
        Cancel = True
    End If
End If
End Sub
Private Sub Resolution_AfterUpdate()
If IsNull([Resolution]) = True Then
    Resolved.Enabled = False
Else
    Resolved.Enabled = True
End If
End Sub

Function checkFields() As String
    If IsNull(Me.Trip__) Then
        checkFields = addToString(checkFields, "Trip #")
    End If
    If IsNull(Me.Comment_Date) Then
        checkFields = addToString(checkFields, "Comment Date")
    End If
    If IsNull(Me.Last_Name) Then
        checkFields = addToString(checkFields, "Last Name")
    End If
    If IsNull(Me.First_Name) Then
        checkFields = addToString(checkFields, "First Name")
    End If
    If IsNull(Me.Medicaid__) Then
        checkFields = addToString(checkFields, "Medicaid #")
    End If
    If IsNull(Me.Appointment_Date) Then
        checkFields = addToString(checkFields, "Appointment Date")
    End If
    If IsNull(Me.Appointment_Time) Then
        checkFields = addToString(checkFields, "Appointment Time")
    End If
    If IsNull(Me.Comment) Then
        checkFields = addToString(checkFields, "Comment")
    End If
End Function

Function addToString(strOrig As String, strToAdd As String) As String
    If strOrig = "" Then
        addToString = strToAdd
    Else
        addToString = strOrig & vbNewLine & strToAdd
    End If
End Function
 
Here would be your basic logic for what I think you are asking:
Click event of checkbox
Check fields for complete
NO - Display message, set focus, uncheck CheckBox, exit sub
YES - continue with disable logic

If they are unchecking the checkbox, it would be different again, but you did not request that.
 
I would suggest that you validate your controls in the forms Before Update event. This way if the user tries to exit the form the code will check to be sure that the required fields have data. Open any form in design view and open the property sheet. Under the Event tab place the cursor in the Before Update event and click the F1 key. You will see some sample code and information on how this event works.

hth,
Jack
 
Thank you both for the responses.

FoFa, you hit it on the head, that is exactly what i need, but i don't know how to go about it. I tried a few different things, but to no avail.

Jack, i don't exactly understand your method, i tried to search help like you said, but got no help. (i don't think they have all the help files installed at my office, i always get prompted to install more)

Thanks
 
got it working!! :)

here is what i used:

Code:
If Resolved.Value = True Then
    Dim strFields As String
    strFields = checkFields
    If strFields <> "" Then
        MsgBox "Please fill in the following fields:" & vbNewLine & vbNewLine & strFields
        Cancel = True
    GoTo inputinfo
    Else: GoTo final
    End If
End If

inputinfo:
    Comment.Enabled = True
    Resolution.Enabled = True
    Appointment_Date.Enabled = True
    Appointment_Time.Enabled = True
    Comment_Date.Enabled = True
    First_Name.Enabled = True
    Last_Name.Enabled = True
    Medicaid__.Enabled = True
    Trip__.Enabled = True
    Trip__.SetFocus
    Resolved.Value = False

final:
End Sub
 

Users who are viewing this thread

Back
Top Bottom