Results 1 to 3 of 3
  1. #1
    zia di is offline Novice
    Windows 10 Office 365
    Join Date
    Sep 2022
    Posts
    1

    Question Command button to open a form filtered by two criteria

    I'm an Access newbie and unsure of what I am missing for the following situation.



    I have a "Startup" form that is like a dashboard when I open my database.
    From here, I have a command button to open ALL records in a different form called "Student Cases".
    There is another command button that allows me to only open the forms for a specific case manager (i.e. Jane Smith). I used the following code:

    DoCmd.OpenForm "Student Cases"
    DoCmd.ApplyFilter , "Casemgr = 'Jane Smith"

    I'm having trouble with the third command button I'm trying to do. I want to filter by one additional criteria (Case Status) to the previous code.
    When I click the command button "Open Cases", I want the following: Open the "Student Cases" form, but only show records where Casemgr=Jane Smith and Casestatus=Open

    I thought I could just do the following:

    DoCmd.OpenForm "Student Cases"
    DoCmd.ApplyFilter , "Casemgr = 'Jane Smith" AND "Casestatus = Open"

    But I get the following error:

    Run-time error '13':
    Type mismatch


    Can someone tell me what I am doing wrong?

    Thank you so much!!!

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Unlikely that is really what you want? I would expectthe values to change?
    However try
    Code:
    "Casemgr = 'Jane Smith' AND Casestatus = 'Open'"
    
    You could do all of that as you open the form?
    Google the OpenForm syntax.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    make a continuous form that shows all records.
    In the header, put unbound controls for the user to enter search criteria.
    When user clicks the Find button, Test all controls for a possible filter then build the where clause:


    Code:
    sub btnFind_click()
    sWhere = "1=1"
    if not isnull(cboState) then   sWhere = sWhere & " and [state]='" & cboState & "'"
    if not IsNull(txtName) then    sWhere = sWhere & " and [Name]='" & txtName & "'"
    if not IsNull(cboGender) then    sWhere = sWhere & " and [Gender]='" & cboGender & "'"
    
    
    
    
     'then filer
    if sWhere = "1=1" then
       me.filterOn = false
    else
       me.filter = sWhere
       me.filterOn = true
    endif
    
    
    end sub

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

Similar Threads

  1. Using command button to query and open form
    By annienelson621 in forum Forms
    Replies: 2
    Last Post: 03-26-2015, 08:05 AM
  2. Replies: 8
    Last Post: 06-25-2014, 08:03 AM
  3. Replies: 6
    Last Post: 05-07-2014, 11:26 AM
  4. Open Form or Command Button problem
    By geordie_taz in forum Forms
    Replies: 3
    Last Post: 12-13-2012, 10:09 AM
  5. Use a command button to open a form
    By johnpaul in forum Forms
    Replies: 24
    Last Post: 09-23-2010, 12:29 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