Results 1 to 12 of 12
  1. #1
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    Brookings, South Dakota, USA
    Posts
    449
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Len(combobox) <> 0 but should (A2k3)

    Hi All.
    In the OnOpen event of a form I am checking the length of the values of both a textbox and a combobox.
    The textbox will return the correct length, 0 to however long it may be, but checking the length of the combobox will return a 1, when I know it should be zero.
    The combobox has 3 columns with widths of 0"; 1.707";0" and the bound column is column1 which is also the primary key of the table which is the RowSource of the combobox. I check it as follows:

    S2 = Nz(Me![cboMyCombo], "")
    If Len(S2) = 0 Then ... etc.

    Using breakpoints, the value of Me!MyCombo = 1 <img src=/S/question.gif border=0 alt=question width=15 height=15>
    It should be = Null.

    Would someone please enlighten me?
    Thank you.

    gdr
    <IMG SRC=http://www.wopr.com/w3tuserpics/gdrezek_sig.jpg>
    "Those who dance are considered insane by those who can't hear the music" - George Carlin

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Len(combobox) <> 0 but should (A2k3)

    The value of a combo box is the value of the bound column. So the combo box may look empty, if the second column is null (the combo box displays the first column whose width is non-zero), but its value might still be non-null.

    If that doesn't explain the behavior you experience, you will have to provide more details.

  3. #3
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    Brookings, South Dakota, USA
    Posts
    449
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Len(combobox) <> 0 but should (A2k3)

    Hi Hans,
    the combobox is used to place a default signature for a record on the main form; e.g. the signature ID is a foreign key in the RecordSource of the form. There are certain records which this field is null.
    What I am trying to do is that *If the field is null, then enter a signature which has been chosen as the default* (I am using a DLookup for this). This last part and others I know work just fine.
    So what I don't understand is why I am getting a value for the combobox when I know that the field it references in the forms RecordSource has a Null value.
    Also, there are no bound values which have an empty visible column in the combobox.
    Thank you Hans.

    gdr
    <IMG SRC=http://www.wopr.com/w3tuserpics/gdrezek_sig.jpg>
    "Those who dance are considered insane by those who can't hear the music" - George Carlin

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Len(combobox) <> 0 but should (A2k3)

    I'm afraid we'd have to see the database to get behind this.

  5. #5
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    Brookings, South Dakota, USA
    Posts
    449
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Len(combobox) <> 0 but should (A2k3)

    Hi Hans,
    Attached, please find a quick and dirty zipped db that does the same thing.
    Just open the popfrmChooseAgency, select an Agency and click Go To.
    If you choose Agency 1, it does have a signature ID entered and will return a length of 1.
    If you choose Agency 2, it does NOT have a signature ID entered and will return a length of 1.
    Thank you.

    gdr

    gdr
    Attached Files Attached Files
    <IMG SRC=http://www.wopr.com/w3tuserpics/gdrezek_sig.jpg>
    "Those who dance are considered insane by those who can't hear the music" - George Carlin

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Len(combobox) <> 0 but should (A2k3)

    In the example you posted, the bound column of the combo box corresponds to AgencyPKID, which is filled in for both agencies, so the problem does not occur. If I change the row source to use SignaturePKID instead of AgencyPKID, the combo box is null for the second agency, so Len(...) is null too, not 1. Why don't you test

    If IsNull(Me.cboAgencyName) Then

    instead of using Len?

  7. #7
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    Brookings, South Dakota, USA
    Posts
    449
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Len(combobox) <> 0 but should (A2k3)

    Hi Hans,
    I'm sorry, but I'm afraid I don't understand.
    Per the attached picture with the combo properties highlighted:
    Are you talking about the combobox in frmAgency or in popfrmChooseAgency?
    I'm afraid I don't see that the bound column of the combobox corresponds to the AgencyPKID or that the RowSource does not use SignaturePKID rather than AgencyPKID. <img src=/S/sorry.gif border=0 alt=sorry width=15 height=15>
    thank you.

    gdr
    Attached Images Attached Images
    <IMG SRC=http://www.wopr.com/w3tuserpics/gdrezek_sig.jpg>
    "Those who dance are considered insane by those who can't hear the music" - George Carlin

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Len(combobox) <> 0 but should (A2k3)

    Sorry, I was looking at the combo box on popfrmChooseAgency.

    The reason for your problem is in the code used to open frmAgency:

    <table><td>DoCmd.OpenForm strFormName</td><td>' The form is opened normally, so opens to the first record with SignaturePKID=1. The On Open even occurs here</td><tr><td>With Forms(strFormName).RecordsetClone</td><td align=right>

  9. #9
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    Brookings, South Dakota, USA
    Posts
    449
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Len(combobox) <> 0 but should (A2k3)

    Hi Hans,
    Thank you.
    The cart before the horse, kinda thing.
    <img src=/S/woops.gif border=0 alt=woops width=58 height=36>

    gdr
    <IMG SRC=http://www.wopr.com/w3tuserpics/gdrezek_sig.jpg>
    "Those who dance are considered insane by those who can't hear the music" - George Carlin

  10. #10
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Len(combobox) <> 0 but should (A2k3)

    I've found that the most reliable way to check for a combo box being "empty" (that is, nothing selected) is to check for the .ListIndex property being = -1.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  11. #11
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    Brookings, South Dakota, USA
    Posts
    449
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Len(combobox) <> 0 but should (A2k3)

    Hi Marty,
    Thank you.
    However in the OnOpen event this still "reads" the record when the form opens and not the record I eventually go to.
    So, I know that eventually the OnCurrent event will get the correct record and use it from there.

    gdr
    <IMG SRC=http://www.wopr.com/w3tuserpics/gdrezek_sig.jpg>
    "Those who dance are considered insane by those who can't hear the music" - George Carlin

  12. #12
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Len(combobox) <> 0 but should (A2k3)

    I'm sorry, but I don't understand your problem. In your original message, you didn't mention anything about reading and displaying records.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

Posting Permissions

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