Results 1 to 7 of 7
  1. #1
    Bongobob21 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    29

    Using Subform for Searchcriteria + relating one searchfield to several columns

    Hello,

    I have two questions for this post.

    1. I created a form with some search-fields which are related to a query. Then I added a Subform in which I put some more Search criteria (So that I can easily hide and unhide those additional searchfields). It sounds strange but is necessary ;-). Now I related those searchfields in the subform to the same query. When I run that query a window pops up that I should put in a value in all those searchfields which are in the subform. But I told Access that it should display all rows, if there is no value in those searchfields. Just as I did it with the Searchcriteria in the Main form. Do I have to do something special, when I have a query which is related to two Forms?

    2. I want a searchfield to search in three different columns. Usually the value will just be found in one of those columns. As the Table I search is very long and has many searchfields and multiple of those will relate to more than one column, is there an easy way to do it in VBA? As I did it by using the "or" field when designing a query, but this seems very slow and unstable.

    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
    Build a query using the key in the master form as criteria. Also use OR for the 3 fields you want to search in.

    select * from table where [keyID] = forms!frmMAster!txtKey and (tbl.[field1] = forms!frmMaster!txtFind OR tbl.[field2] = forms!frmMaster!txtFind or tbl.[field3] = forms!frmMaster!txtFind)

  3. #3
    Bongobob21 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    29
    Thanks a lot, So I put this code in the Column it should search in the query. But what is the Form key? I never heard that term.

    Thanks!

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    Not a 'form key', but the table key for the data in the subform is ON the form.
    The seach box would be on the header of the master form. You already know the master key, so your search would encompass the subform fields, USING the master key and those fields.

  5. #5
    Bongobob21 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    29
    The problem is, that I am working with linked tables, as an Excel-Spreadsheet is my datasource. As far as I know, it is not possible to put Primarry keys into a linked Table?

    Furthermore I am linking usually one table with 2 - 3 other tables, therefore I don't know if a primary key would help.

    (Sorry If I am writing bullshit, I am totally new to Access)

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    Primary key is a unique identifier in one table that is also present in another table that serves as foreign key (usually not unique in the related table). A PK/FK can be composed of multiple fields - something I try very hard to avoid. So link the tables on as many fields as needed to uniquely identify the record association.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Bongobob21 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    29
    I Linked all tables together, my issue is, that I am not able to determine a primary key, as the tables are not created in access. The tables are just linked to an excel spreadsheet. Can you give me an advice how to set a primary key when linking an excel table to access?

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

Similar Threads

  1. User defined searchfield
    By Bongobob21 in forum Forms
    Replies: 13
    Last Post: 04-17-2015, 01:14 AM
  2. Autowidth for columns in subForm
    By rockstar283 in forum Access
    Replies: 13
    Last Post: 07-10-2014, 09:26 PM
  3. Subform with dynamic number of columns
    By modbass in forum Programming
    Replies: 1
    Last Post: 12-15-2011, 03:39 AM
  4. Visible property in subform columns
    By MDB in forum Forms
    Replies: 3
    Last Post: 09-03-2011, 06:46 PM
  5. Replies: 2
    Last Post: 03-31-2010, 01:56 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