Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AUTOMATICALLY POPULATE A CHECKBOX

Status
Not open for further replies.

joanl

Technical User
Apr 10, 2001
20
US
I have a form with a name field and social security field and checkoxes that are to be checked if the social security number is corrected or added on an existing record. I have some code that places a check into the SSN Corrected checkbox whenever the SSN is changed. However, I'm unable to check the SSN Added box using the same type of code. The SSN Added checkbox is to be checked only if the name field was already filled and the Social Security Number field was blank... not a new record. Here is the code I'm attempting to use... no laughing please. :-D
Code:
Private Sub SOCIAL_SECURITY_AfterUpdate()

If (Me.sduNAME.Value <> Null Or Me.sduNAME.Value <> &quot;&quot;) Then
    If [SOCIAL_SECURITY].OldValue = Null Or SOCIAL_SECURITY.OldValue = &quot;&quot; Then
        Me.SSN_Added.Value = True
        Me.SSN_Corrected.Value = False
    End If
    
    If SOCIAL_SECURITY.OldValue <> Null Or SOCIAL_SECURITY.OldValue <> &quot;&quot; Then
        Me.SSN_Corrected.Value = True
        Me.SSN_Added.Value = False
    End If
End If
Any tips are greatly appreciated.

 
Hi Joan,

I think that I know what you want to do, but I'm not sure. Give this a try.

If Nz(sduNAME.Value <> &quot;&quot;) Then
If Nz(SOCIAL_SECURITY.OldValue) <> Nz(SOCIAL_SECURITY.Value) Then
SSN_Corrected.Value = True
Else
SSN_Corrected.Value = False
End If

If Nz(SOCIAL_SECURITY.Value) <> “” Then
SSN_Added.Value = True
Else
SSN_Added.Value = False
End If
End If

What state should the check boxes be in if the name is blank? Your outer If structure only sets the check boxes if Name is not blank. dz
 
By the way, this is how I assumed that you wanted the logic to work.

If the name isn't blank and the SSN changed, check the corrected box.

If the name isn't blank and the SSN did not change, uncheck the corrected box.

If the name isn't blank and the SSN is not blank, check the added box.

If the name isn't blank and the SSN is blank, uncheck the added box.

This is kind of confusing logic, or maybe it's just too late in the day :eek:)... it might help to write it out like I've got here to help me figure out what you want to do.

Thanks,
dz
 
Hi DZ,

Thanks for your quick response. I'll try to put a little background on this. This is based on existing records in the database, so a name must be in that field. The SSN field can be blank or already have a SSN in the field. If the user receives a SSN to enter,

1. It will be new info in the blank SSN field, so:
Added Box = Checked
Corrected Box = Unchecked.
Or

2. If there was already info in the SSN field, it will be edited, so:
Corrected Box = Checked
Added Box = Unchecked

Is this as clear as mud now?

I just tried the code you provided, but it puts a check into both boxes now. At least it's now putting a check into the Added box... I couldn't get it to do that myself.%-)

I'll take another look to see if my If statements need to be rearranged. If you have any clues for the clueless, I'd appreciate it.

Thanks for your help,
Joan
 
Hi, I just wanted to make sure that I understand. You have a table with names and SSNs. Some of the records have a name but no SSN entered. Some of the records have a name and SSN. Let's look at them one case at a time.

Record has a name but no SSN:

If the user adds a SSN, check the added box.
Otherwise uncheck the added box.
Uncheck the corrected box? (this isn't done in my last code)

Record has a name and an SSN:

If the user changes the SSN, check the corrected box.
Otherwise uncheck the corrected box.
Uncheck the added box? (this isn't done in my last code)

Is this right so far?

What happens if the user deletes an existing SSN? i.e. blanks the filed out entirely.

If the name must always be entered, do you really need to test for a null name? If not, you could eliminate the outer If structure.

The reason that both boxes are being checked is because there's no code to support where I wrote (this isn't done in my last code). I wasn't sure if you wanted to uncheck those boxes under those conditions. I can send you a correction if you clarify.

Thanks, dz
 
Hi dz,

After some manipulating with the code, it's finally works.
I had tried the nz function earlier, but I guess I wasn't phrasing things right.

This is what I finally used:
Code:
If Nz(sduNAME.Value <> &quot;&quot;) Then
    If Nz(SOCIAL_SECURITY.OldValue) <> &quot;&quot; Then
        SSN_Corrected.Value = True
        SSN_Added.Value = False
    ElseIf Nz(SOCIAL_SECURITY.OldValue) = &quot;&quot; Then
        SSN_Added.Value = True
        SSN_Corrected.Value = False
    End If
End If
Thanks for helping point me in the right direction.

Joan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top