Results 1 to 12 of 12
  1. #1
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568

    Open form with filter and turn off possibility to clear it or change it

    Hi,

    i am trying to open form :



    Code:
    DoCmd.OpenForm "frmSlownikStatus", acFormDS, , "Section_name= '" & stringValue & "'"
    It is ok besides that this command is opening my form with possibility to change by user inputed filter.
    It is possible to open form with filter but not allow to change it by user?

    Thank you,
    Jacek Antek

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Try:
    Code:
    DoCmd.OpenForm "frmSlownikStatus", acFormDS, , "Section_name= '" & stringValue & "'"
    Forms!frmSlownikStatus.AllowEdits = False
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    Thank you Bob,

    It will block form for editing.

    But now if user wants to add or edit field within subform - there will be a problem...?

    Best wishes,
    Jacek

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Quote Originally Posted by jaryszek View Post
    Thank you Bob,

    It will block form for editing.

    But now if user wants to add or edit field within subform - there will be a problem...?

    Best wishes,
    Jacek
    The code will indeed stop users from editing a record. I thought that was the requirement
    If you want to allow editing of the record after it has been opened then you would need to use the code:
    Code:
    Me.AllowEdits = True
    perhaps with a button or perhaps on the Double Click event of a control.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    hmm thanks.

    Maybe i should do event macro if you are clicking into record within subform set allowedits = true,
    if you are clicking outside form or in filter = allowedits = false.

    Anyone had the problem like me? How did you solve it?

    Thanks,
    Jacek Antek

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Quote Originally Posted by jaryszek View Post
    hmm thanks.

    Maybe i should do event macro if you are clicking into record within subform set allowedits = true,
    if you are clicking outside form or in filter = allowedits = false.

    Anyone had the problem like me? How did you solve it?

    Thanks,
    Jacek Antek
    If the solution I proposed earlier does not fulfill your requirements please explain why.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  7. #7
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    Ok Bob,

    I have dictionary table with statuses for different sections : "ZUS" and "SOD_Kadry".

    And now i have to give opportunity to open this table by user and add new row by him.
    Table should open only on filtered records.

    If user is logged section name is assigned to him via tempvar.

    So example:
    User ljar01 has section_name "ZUS"
    Now i want to add new status name into table "tbl_Status_name" so i am opening the form and i see only my section rows.
    Because if i saw other section name - "SOD_Kadry" i could change it even by mistake.

    Best wishes,
    Jacek
    Attached Thumbnails Attached Thumbnails Table.png  

  8. #8
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Quote Originally Posted by jaryszek View Post
    Ok Bob,

    I have dictionary table with statuses for different sections : "ZUS" and "SOD_Kadry".

    And now i have to give opportunity to open this table by user and add new row by him.
    Table should open only on filtered records.

    If user is logged section name is assigned to him via tempvar.

    So example:
    User ljar01 has section_name "ZUS"
    Now i want to add new status name into table "tbl_Status_name" so i am opening the form and i see only my section rows.
    Because if i saw other section name - "SOD_Kadry" i could change it even by mistake.

    Best wishes,
    Jacek
    So, using the code in post #2 "stringValue" would be assigned the value "ZUS" which would filter the records return. The next line of code would prevent a user from editing any of the current records but would allow the user to add new records.
    How is this different from your requirement?
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  9. #9
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    Your code is great but:

    1. I want to give user possibility to edit data.
    2. I want to hide other sections from users. Only their section should be seen.

    Best wishes,
    Jacek

  10. #10
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Quote Originally Posted by jaryszek View Post
    Your code is great but:

    1. I want to give user possibility to edit data.
    2. I want to hide other sections from users. Only their section should be seen.

    Best wishes,
    Jacek
    But that's what the first line of code that YOU originally posted does. It applies a filter to the form so that only records for the value assigned to "stringValue" are returned and allows the user to edit any of the controls. I'm really confused.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  11. #11
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    Yes, but users can still filter table...and see section of others...:

    Click image for larger version. 

Name:	Table.png 
Views:	6 
Size:	19.0 KB 
ID:	31337

    Jacek

  12. #12
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Ah. Now I understand.
    I would just open the form with:
    Code:
    DoCmd.OpenForm "frmSlownikStatus", acFormDS
    and then use the next line of code to set the forms Record Source property with an SQL "SELECT" statement which would include the criteria that you originally used as a filter for the form. If you need help with the SELECT statement, then post a copy of the existing Record Source property or the SQL statement of the query used
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

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

Similar Threads

  1. How to clear filter when I close out tables?
    By wuzhuo77 in forum Access
    Replies: 5
    Last Post: 07-21-2015, 11:16 AM
  2. Replies: 3
    Last Post: 09-23-2013, 06:42 AM
  3. Filter form on open
    By Xarkath in forum Forms
    Replies: 8
    Last Post: 07-17-2013, 10:51 AM
  4. clear filter
    By amerifax in forum Access
    Replies: 2
    Last Post: 05-30-2013, 05:11 AM
  5. clear past data during form open
    By newaccess in forum Forms
    Replies: 1
    Last Post: 01-09-2013, 10:55 AM

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