Results 1 to 8 of 8
  1. #1
    bubai is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162

    How to clear combobox values properly.

    Hi,


    In my Search form which I use to open filtered query I have placed a "Clear All" button to remove all the combobox values and start a fresh query. However, if I click the button combobox values get clear but the query fails. But if I don't use the button the query works. In the following pic I showed my form in Pic 1 and the error massage in Pic 2. Click image for larger version. 

Name:	Join.jpg 
Views:	13 
Size:	98.9 KB 
ID:	42828
    The code behind the "Clear All" (named Command6) button is
    Code:
    Private Sub Command6_Click()
    Me.cboBrandID.Value = ""
    Me.cboCatagory.Value = ""
    Me.cboDes.Value = ""
    Me.cboFiscalYear.Value = ""
    Me.cboStation.Value = ""
    Me.cboSupplierID.Value = ""
    Me.txtBankValue.Value = ""
    Me.cboCNF.Value = ""
    End Sub
    However, if I set control's .RowSource property to "", the combobox doesn't show anything at all.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Don't use .value
    just: cboBox=""

  3. #3
    bubai is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    Quote Originally Posted by ranman256 View Post
    Don't use .value
    just: cboBox=""
    Still the same problem. Error no 2950.

    Click image for larger version. 

Name:	Join.jpg 
Views:	12 
Size:	40.8 KB 
ID:	42829

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    I usually set the values to null - me.cboWhatever = null
    If you are constructing the query or filter with code be careful to test for the right value, either a null or a ZLS whichever you use.

    edit: show us the macro or code your using

  5. #5
    bubai is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    Quote Originally Posted by moke123 View Post
    I usually set the values to null - me.cboWhatever = null
    If you are constructing the query or filter with code be careful to test for the right value, either a null or a ZLS whichever you use.
    Cheers mate!
    It's working now. But I didn't understand what you meant by ZLS.
    Also can you answer me one more thing? That is - What is the data type that comes from the combobox? It seem that it fits in both numeric and string fields.

  6. #6
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    ZLS is a Zero Length String. It is not the same as a null. If you look in the field properties of your table there is an entry for allowing zero length strings.
    You can test for both null and ZLS with something like nz(MyValue,"") <> ""

    As far as the datatype returned by a combobox I'm not really sure. I know that I have run into situations where I've gotten Data mismatch errors but they are easy to fix by coercing the correct datatype - ie. Clng(me.MyCombo.Column(2)) or cDate(me.MyCombo)

  7. #7
    bubai is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    But is it a good idea to allow for zero length string?

  8. #8
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Quote Originally Posted by bubai View Post
    But is it a good idea to allow for zero length string?
    Depends.
    I think thats one of those questions where you may get several differing opinions.
    I usually avoid them if I can.
    Heres a link to one discussion, there are many https://social.msdn.microsoft.com/Fo...orum=accessdev

    for a pretty good primer on nulls https://www.utteraccess.com/topics/1553733?post=unread

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Clear combobox on click
    By khayward in forum Forms
    Replies: 1
    Last Post: 07-03-2018, 08:59 AM
  2. Clear the Combobox using a button
    By CharissaBelle in forum Forms
    Replies: 2
    Last Post: 04-28-2016, 01:24 PM
  3. Clear values on query based form
    By JackieEVSC in forum Forms
    Replies: 1
    Last Post: 04-21-2016, 11:17 AM
  4. Replies: 2
    Last Post: 04-09-2016, 01:23 PM
  5. clear field values
    By surrendertoo in forum Queries
    Replies: 0
    Last Post: 02-23-2008, 10:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums