Results 1 to 12 of 12
  1. #1
    Join Date
    Nov 2011
    Posts
    413

    Unanswered: Problem with if statement

    If CupidAlert = True Then
    Label184.Visible = True
    Else
    Label184.Visible = False
    End If


    Label184 is set to be visible
    Cupid Alert is a check box set in my table as data type yes/no and format true/false
    I use this code on the current event for my form. It does not work, label is visible all the time.

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Works fine for me! You understand that with the code only being in the Form_Current event, the Label will not disappear until you leave the Record and return, right? For the Label to vanish as soon as you tick the CupidAlert Checkbox, you'd also need the same code in the CupidAlert_AfetrUpdate event.

    Another possible reason for failure, on your end, could be a misspelling of one or more of the Controls involved. Your code, for instance, gives the Checkbox name as CupidAlert, without a Space between Cupid and Alert. But in your narrative, you give it as Cupid Alert with a Space between Cupid and Alert! As you've been told before, this kind of thing has to be exact, in VBA!

    I'd also double-check the Label name; depending on the size of the text on your screen, as well as the particular font you use, Label84 and Label184 can look remarkable alike, which they aren't, if you look closely!

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Nov 2011
    Posts
    413
    Thing about it is that the label stays visible no matter if you go back and forth to records or not. I believe it has to do something to do with the fact that I also have other If statements on the current an after update events for the form.

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Then you need to post the entire AfterUpdate event! No one here can guess what else you have going on in it! We cannot evaluate whet we cannot see!

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    Join Date
    Nov 2011
    Posts
    413
    Private Sub Form_AfterUpdate()
    If CupidAlert = No Then
    Label184.Visible = True
    Else
    Label184.Visible = False
    End If
    Me.Refresh

    Me!Labelsearch.Visible = True
    If Status = 2 Then
    Label18.Visible = True
    Else
    Label18.Visible = False
    End If
    Me.Requery
    If Not IsNull(GirlID) Then
    LastContacted = Date
    End If

    Me.Refresh
    End Sub

  6. #6
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    What can I say? You change your story every time you tell it! You've done it on previous threads on this forum, and you're doing it again, and it makes it almost impossible to help you! First you say

    Quote Originally Posted by Burrina View Post
    If CupidAlert = True Then
    Label184.Visible = True
    Else
    Label184.Visible = False
    End If
    If CupidAlert is ticked then Label184 is Visible.

    Then you say

    Quote Originally Posted by Burrina View Post
    If CupidAlert = No Then
    Label184.Visible = True
    Else
    Label184.Visible = False
    End If
    If CupidAlert is not ticked then Label184 is still Visible!

    Which is it? It can't be both!

    You also need to pay strict attention to advice that you're given here, on the forum! No one said anything about dealing with this in the Form_AfterUpdate event, you were told to put it in the CupidAlert_AfterUpdate event!

    If you want our help, in accomplishing your goals, you first need to be sure of what those goals are, before posting them. And you need to listen to us, carefully!

    Now ait back, think through what you're trying to accomplish, and tell us, in plain language, what you're trying to do here.

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  7. #7
    Join Date
    Nov 2011
    Posts
    413
    If CupidAlert = True Then
    Label184.Visible = True
    Else
    Label184.Visible = False
    End If

  8. #8
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    If your Label is named

    Label184

    and your Checkbox, on the Form, is named

    CupidAlert

    then this code

    Code:
    Private Sub CupidAlert_AfterUpdate()
    
    If Me.CupidAlert = True Then
    
     Label184.Visible = True
    
    Else
    
     Label184.Visible = False
    
    End If
    
    End Sub

    will make Label184 become Visible when the CupidAlert Checkbox is ticked and Invisible when it is not ticked or is unticked.

    This code

    Code:
    Private Sub Form_Current()
    
    If Me.CupidAlert = True Then
    
     Label184.Visible = True
    
    Else
    
     Label184.Visible = False
    
    End If
    
    End Sub


    will keep Label184 either Visible or Invisible, as appropriate, when moving from Record-to-Record.

    I assume that your app is in a 'Trusted' location, if you're running Access 2007/2010, since you have other code, as posted elsewhere, that actually runs.

    If the above doesn't work for you need, as I said in Post #2, to check the exact names of the Checkbox and Label.

    If the names are correct, the code is placed in the events as I gave above (as opposed to placing it anywhere you feel like placing it) and it still does not run properly, your only real alternative is to ZIP up your file and attach it here to a post, for us to look at.

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  9. #9
    Join Date
    Nov 2011
    Posts
    413
    That code erred out on the Me.CupidAlert .... but it still does not work even if I remove the Me in front ???? Don't understand why because I have an exact if statement with another control and it works fine. This works on another control.
    If Blocked = True Then
    Label137.Visible = True
    Else
    Label137.Visible = False
    End If

    Blocked is a checkbox just like CupidAlert is

  10. #10
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    If you're positive that the name of the Checkbox is CupidAlert, just like that, nothing else, no spaces, then maybe the Checkbox Control is corrupted. We think of corruption in terms of Forms or even entire databases, but individual Controls can and do get corrupted, as well.

    Try Deleting the existing Checkbox, then re-create it!

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  11. #11
    Join Date
    Nov 2011
    Posts
    413
    Thanks for all of your help. Dont know if the control was corrupt or not but I did delete it, compile and load the form again. This time I changed the caption to CupidAlert and it worked. The control is actually named Cupid Alert notice the space. I dont know why access works on the control and other times it has to work on the name itself, I am confused on this, oh well, it is working and now I know to check both options and choose which one works.

  12. #12
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Glad you got it working!

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

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