Results 1 to 8 of 8
  1. #1
    cactuspete13 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Dec 2012
    Posts
    53

    Open form based on search criteria

    I am trying to set up a form (Switchboard) that will open another form (Case Form) or report (Case Report) based on a series of criteria (Fiscal Year, Quarter, Case Number). On the switchboard there will be three text blocks where users can enter one, two or all three of the above mentioned items, hit either the View Case Form or View Case Report button to view only records that match those criteria. I've attached the VBA code I am working on right now, but when I search using 2013 for the Fiscal Year, I get a "Run-time Error: 13 Type mismatch" message. Below is the setup of the tables and forms, and the vba code.

    Table: tblCase; with FiscalYear, Quarter, CaseNbr fields
    Form: Switchboard; three text boxes named SearchFY, SearchQuarter, and SearchCaseNbr, and button Command7 (haven't changed the name yet)
    Form: Case Form; Controls for FiscalYear, Quarter, and CaseNbr

    VBA Code

    Private Sub Command7_Click()

    DoCmd.OpenForm "Case Form", , , "[FiscalYear] like '" & Me!SearchFY & "*' and [Quarter] like '" & Me!SearchQuarter * "*'"

    End Sub



    Any help would be appreciated

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What are the data types of the fields? Do you really want/need wildcards?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    cactuspete13 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Dec 2012
    Posts
    53
    All are number except quarter which is text (dropdown option, 1st Quarter, 2nd...). Eventually there will be 4 options for searching and I am trying to get it so that users can search for all cases submitted by John during 1st Quarter 2013, or for all records during an entire fiscal year, quarter or by person. Obviously if they know the exact case number that's easier.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You don't want the single quotes around numeric values. Personally I wouldn't use Like and wildcards unless necessary.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    cactuspete13 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Dec 2012
    Posts
    53
    Ok, I've moved everything to one form, still trying to do the same thing, type person's name in the text block named SearchOwner to get the form to filter all records to only show when that person is the CaseOwner. I've tried both ApplyFilter macro with the Where Condition set to =[SearchOwner], and I've tried VBA: DoCmd.ApplyFilter , "[CaseOwner] = [SearchOwner]" No luck on either. Any ideas?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Names (text fields) do require the delimiters. Similar to this:

    http://www.baldyweb.com/wherecondition.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    cactuspete13 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Dec 2012
    Posts
    53
    Awesome! Works like a charm! Managed to figure out adding multiple criteria but ran into another problem: When I add a second parameter it forces me to enter a criteria. How do I tell it that it is ok if the fields are empty?

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I would build the string item by item, and only add each if the user has entered something.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Search form criteria
    By atom in forum Forms
    Replies: 3
    Last Post: 04-03-2012, 06:42 AM
  2. Open 1 of 2 Forms based on Criteria
    By DCV0204 in forum Forms
    Replies: 28
    Last Post: 11-23-2011, 03:09 PM
  3. Multiple Search Criteria Form
    By J77TDC in forum Forms
    Replies: 3
    Last Post: 08-09-2011, 08:50 AM
  4. Replies: 1
    Last Post: 07-02-2010, 03:55 AM
  5. Open form based on Subform criteria
    By Suzan in forum Programming
    Replies: 0
    Last Post: 04-25-2006, 02:28 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