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!

Problems in Program to mark Check box as True if Condition Exists 1

Status
Not open for further replies.

RobotMush

Technical User
Aug 18, 2004
197
US
I have a form for my clients and a subform for the Data that I am entering for that client. Since I am not entering Data for All the clients I have a Check Box in my form to mark the client as having data in the subform. I was thinking the following program would work...

Private Sub chkHypLnk_AfterUpdate()
If IsNull([HypLnk-sfrm].[HypLnk]) Then
Exit Sub
Else
chkHypLnk = True
End If

End Sub

The Check box is called "chkHypLnk" and in my subform called "HypLnk-sfrm" I have a Hyperlinked Text Box called [HypLnk] When I have placed a Hyperlink in the Subform text box I am wanting the Check Box in my form to become True. Am I going about this the right way?

Thanks for any and all your help

RobotMush (Technical User) Self Taught
 
How are ya RobotMush . . .

The question is: What do you want to do if a record in [blue]Clients has no subform data[/blue]?

Calvin.gif
See Ya! . . . . . .
 
ACEMAN!!! MY HERO!!! So good to hear from you man!

>The question is: What do you want to do if a record in >Clients has no subform data?

If a Record in Clients has no subform Data then chkHypLnk would be false...
*Flash of insight or brain burp*
So rather than have exit sub in the program have
chkHypLnk = False

That what you getting at?

I'm going to try it and find out.

Thank you

RobotMush (Technical User) Self Taught
 
Ok, after the thought shift suggestion from AceMan the program has been altered to this...

Private Sub chkHypLnk_AfterUpdate()

If IsNull([HypLnk-sfrm].[HypLnk]) Then
chkHypLnk = False
Else
chkHypLnk = True
End If

End Sub

And it still does not work

Anybody know what I might be doing wrong?

Thanks for all help and suggestons

RobotMush (Techinical User) Self Taught
 
Well, chkHypLnk_AfterUpdate event is the wrong place to put your code. Because it won't fire until something changes its value, and its value won't change until the code fires, etc., etc.

Since you want the checkbox to be checked when HypLnk is changed, that is the place to put your code (i.e. in the subform).
Code:
Private Sub HypLnk_AfterUpdate()
    
    'Nz will catch both Null and empty strings
    If Nz(Me.HypLnk,"") = "" Then
        'Note - I don't know the name of your main form
        Forms("MyMainForm").Controls("chkHypLnk") = False
    Else
        Forms("MyMainForm").Controls("chkHypLnk") = True
    End If
    
End Sub
 
RobotMush . . .

Are there other fields besides [blue]HypLnk[/blue] you'd perfer to validate before updating the checkbox?

This is the same a [blue]required set of data[/blue]. You'd know if required was complete!

Calvin.gif
See Ya! . . . . . .
 
Thank you JoeAtWork and Aceman, I have printed out your suggestions to better reread and understand what you suggest.
Will let you know how it goes.

Thanks for all the help
RobotMush (Technical User) Self Taught
 
Aceman, taking your suggestion of other fields to check I have re-written the program to...

Private Sub chkHypLnk_AfterUpdate()
If ([HypLnk-sfrm].[FileType]) = "PDF" Then
[HypLnk-frm].[chkHypLnk] = True
Else
If ([HypLnk-sfrm].[FileType]) = "TIF" Then
[HypLnk-frm].[chkHypLnk] = True
Else
[HypLnk-frm].[chkHypLnk] = False
End If
End If
End Sub

Still doesn't work...

JoeAtWork
Taking your suggestion I pulled in my chkHypLnk box to my subform and created the following code

Private Sub chkHypLnk_AfterUpdate()

If Nz([HypLnk-sfrm].[FileType],"") = "" Then
Forms([HypLnk-sfrm].[chkHypLnk]) = False
Else
Forms([HypLnk-sfrm].[chkHypLnk]) = True
End If

End Sub
And that does not work either.

This is causing my mind to take on my nick RobotMUSH

Thank you for your help.

RobotMush (Technical User) Self Taught
 
As I said in my original post, it will not work the way you want if the code is in the AfterUpdate event of the checkbox. You are putting the cart before the horse.

You are putting the code that automatically updates the checkbox in the event that fires after the checkbox has been updated. You have to run the code somewhere else.

So, here's what you can do. Create a centralized procedure that can be called from the AfterUpdate of any control that might affect the value of the checkbox. Place this in the code of your subform:
Code:
private sub UpdateCheckbox()
    If Nz([HypLnk-sfrm].[FileType],"") = "PDF" Then
        [HypLnk-frm].[chkHypLnk] = True
    Else
        If Nz([HypLnk-sfrm].[FileType],"") = "TIF" Then
            [HypLnk-frm].[chkHypLnk] = True
        Else
            [HypLnk-frm].[chkHypLnk] = False
        End If
    End If
End Sub

Note, I've added a couple of Nz's to be a little more safe.

In the AfterUpdate event of the FileType textbox, call your central procedure:
Code:
Private Sub FileType_AfterUpdate()
    UpdateCheckbox
End Sub
 
Thank you JoeAtWork, I believe I can follow your program logic, will have to study it before I totally understand it. I will let you know how it goes.

Thanks again for your help

RobotMush (Technical User) Self Taught
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top