Results 1 to 4 of 4
  1. #1
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108

    how to do a combo box criteria ?

    I have a combo box for


    Source - 3 options ( Epos , SAP and All)

    Click image for larger version. 

Name:	Capture.JPG 
Views:	16 
Size:	30.4 KB 
ID:	21912


    Eg.
    If i click on Source - SAP
    I wanna display the the person data who have the same name & same gender & same postal code and same dob. (Which source = SAP)

    Any idea on how to do this criteria ?
    by vba or any way ?

    Thanks in advance

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    IF
    this is a continuous form
    AND
    you are filtering on 1 combo box

    in the combo box AFTERUPDATE event:
    Code:
    me.filter = "[field] = ' " & cboBox & " ' "    'single quotes exagerated for visiblilty.  dont use spaces in reality.
    me.filterOn = true

    if you are using MORE than 1 combo:
    You cant use form boxes in a query if there's nothing in them..so..
    Test all controls for a possible filter then build the where clause.


    Code:
    
    if not isnull(cboState) then   sWhere = sWhere & " and [state]='" & cboState & "'"
    if not IsNull(txtName) then    sWhere = sWhere & " and [Name]='" & txtName & "'"
    if not IsNull(chkContact) then sWhere = sWhere & " and [Contact]=" & chkContact.value
    
    
        'remove 1st And
    if len(sWhere)>0 then sWhere= mid(sWhere,5)
    
    
      'just use the filter
    iLen = Len(sWhere) - 5
    If iLen <= 0 Then
        me.filterOn = false
    Else
        me.filter = sWhere
        me.filterOn = true
    End If

  3. #3
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108
    Quote Originally Posted by ranman256 View Post
    IF
    this is a continuous form
    AND
    you are filtering on 1 combo box

    in the combo box AFTERUPDATE event:
    Code:
    me.filter = "[field] = ' " & cboBox & " ' "    'single quotes exagerated for visiblilty.  dont use spaces in reality.
    me.filterOn = true

    if you are using MORE than 1 combo:
    You cant use form boxes in a query if there's nothing in them..so..
    Test all controls for a possible filter then build the where clause.


    Code:
    
    if not isnull(cboState) then   sWhere = sWhere & " and [state]='" & cboState & "'"
    if not IsNull(txtName) then    sWhere = sWhere & " and [Name]='" & txtName & "'"
    if not IsNull(chkContact) then sWhere = sWhere & " and [Contact]=" & chkContact.value
    
    
        'remove 1st And
    if len(sWhere)>0 then sWhere= mid(sWhere,5)
    
    
      'just use the filter
    iLen = Len(sWhere) - 5
    If iLen <= 0 Then
        me.filterOn = false
    Else
        me.filter = sWhere
        me.filterOn = true
    End If
    What's the different between afterevent and on change ?

  4. #4
    Mahendra1000 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2013
    Posts
    101
    Quote Originally Posted by fluffyvampirekitten View Post
    What's the different between afterevent and on change ?
    AfterUpdate fires when the user leaves a control after having done something in it. If the user tabs into a control and tabs out without typing or changing the value, it won't fire.

    Change fires *at every keystroke* in the control - i.e. whenever the Text (as opposed to Value) property of the control is changed.

    AfterUpdate is almost surely what you want, if you want to redo a calculation when a new value has been established in your control. Change is useful if you want to trap individual keystrokes.

    I just googled it

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

Similar Threads

  1. Replies: 11
    Last Post: 09-03-2015, 11:12 AM
  2. Query criteria from Combo box
    By cbende2 in forum Access
    Replies: 24
    Last Post: 07-13-2015, 03:05 PM
  3. Combo box in query criteria
    By nittany77 in forum Queries
    Replies: 19
    Last Post: 08-19-2014, 04:02 AM
  4. Replies: 11
    Last Post: 08-06-2014, 09:47 AM
  5. Please Help: Combo Box Criteria Statement
    By mikeone610 in forum Queries
    Replies: 15
    Last Post: 01-27-2013, 09:27 PM

Tags for this Thread

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