Results 1 to 10 of 10
  1. #1
    Join Date
    Sep 2003
    Posts
    122

    Unanswered: Subform If-Then Statement (Help)

    I have a subform, based on a stored procedure, that returns notes of type1 or type2. Some customers may not have any notes, so the subform is blank.

    I am trying to have a pop-up form open if the customer has any notes that are type2. I'm not sure what if-then statement I should be using on the Form's Current event. I only want the pop-up form to open if a type2 note is present. Otherwise, it stays closed.

    Thanks for any help.

  2. #2
    Join Date
    Feb 2004
    Posts
    142
    If the Type1 and Type2 are in a field you can test that field for its contents If fieldName = "Type 2" then
    docmd.open form.
    endif
    KC

  3. #3
    Join Date
    Sep 2003
    Posts
    122
    I've tried that. Here's what happens when I do that. It works if the type2 note is at the top of the subform, but when it is not at the top, or first, it does not work. Also, when I do this, I get an error, "You entered an expression that has no value," if that customer has no notes at all. Any ideas?

  4. #4
    Join Date
    Mar 2004
    Posts
    77

    try this...

    is the type2 note a textbox?

    if it is, you can try:

    if isnull(type2) or type2 ="" then
    DoCmd.openform "your_pop_up_form"
    endif

  5. #5
    Join Date
    Sep 2003
    Posts
    122
    It is a text box, but I'm not sure I understand. If I do, then the code you gave me should read:

    If IsNull(MySubform!NoteType) or NoteType="Type2" Then
    DoCmd.OpenForm "MyPop-upForm"
    End If

    My question though is, won't this open the pop-up form if there is no value? I only want the pop-up form open if the NoteType field is type2. No other time. Also, this code will give me the same problem if the type2 note is not at the top of the subform or the first entry.

    Or, am I supposed to enter the code you gave me as follows:

    If IsNull(Type2) or Type2="" Then
    DoCmd.OpenForm "MyPop-upForm"
    End If

    That just didn't seem right. Let me know what you think. Thanks again for the help.

  6. #6
    Join Date
    Mar 2004
    Posts
    77
    sorry. make a mistake just now.

    should be :

    If MySubform!NoteType="Type2" Then

    DoCmd.OpenForm "MyPop-upForm"

    Else

    Exit Sub

    End If

  7. #7
    Join Date
    Sep 2003
    Posts
    122
    That's what I tried and it didn't work.

    Here's what happens when I do that. It works if the type2 note is at the top of the subform, but when it is not at the top, or first, it does not work. Also, when I do this, I get an error, "You entered an expression that has no value," if that customer has no notes at all. Any ideas?

  8. #8
    Join Date
    Mar 2004
    Posts
    77
    is the information in this application sensitive? if not, can u post the file?
    i can't really work out the code without looking at the acutal thing.

  9. #9
    Join Date
    Sep 2003
    Posts
    122
    First, thanks for the continued help. The info is sensitive, but I think I can give you a pretty clear explanation of what's going on and what I am doing.

    I have a main form with a continuous-form subform that is based on a stored procedure. We'll call the main form "mainform" and therefore the subform will be Forms!Mainform!Subform.

    The stored procedure that the subform is based on yields the correct results. It displays a list of notes and the type of note in text boxes on the subform. Sometimes, a customer will not have any notes, so the stored procedure yields no results.

    I have a second form that we'll call "Popup." I want this form to pop-up if and only if a customer has a note that is "type2." I have tried the code that we posted earlier and I am having two issues. First, the pop-up form is only displayed if the "type2" note is at the top of the continuous-form subform. It does not seem to look any further down the list. If it is not the first note displayed, then the pop-up form is not opened. The second issue is I receive the error I described above for any customer that has no notes at all. It seems that because the customer has no notes, the program does not know how to respond to the function, which is causing the error.

    Perhaps the If-Then statement should be something that looks at the stored procedure results and says if the results have a note with type2, then open pop-up form. If there are no results or there are no notes with type2 then do nothing. Just a thought.

    Thanks again.

  10. #10
    Join Date
    Sep 2003
    Posts
    122
    I got it. I ended up using a Dlookup function. Thanks again for your willingness to help.

Posting Permissions

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