Results 1 to 11 of 11
  1. #1
    cybermonkey is offline Novice
    Windows 10 Office 365
    Join Date
    Jan 2021
    Posts
    16

    Help with code

    I have the following code:

    Dim RecordId As Integer
    Dim asFilter As String
    asFilter = Me.RCA_Number
    MsgBox (asFilter)


    DoCmd.OpenForm "Action Items", acNormal, asFilter, acFormEdit, acWindowNormal
    Forms("Action Items").Requery

    What this is supposed to do it open a form with only showing record filtered by the field that was double clicked.
    It's working for the most part, asFilter is getting set to be the proper value, but the form being opened to display the data is not showing any data. I am most likely missing something on the DoCmd line, but not seeing it, any other set of eyes to see what I am missing would be appreciated.
    Thanks.

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2019
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Perhaps:
    asFilter = "[NameOfFieldToFilter] = " & Me.RCA_Number
    DoCmd.OpenForm "Action Items", acNormal, , asFilter, acFormEdit, acWindowNormal
    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
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,575
    Think about it. How is Access meant to know which field you are comparing the value to?
    Just because you clicked on it?
    If you actually wanted to do that, you would have to identify which field it is and set the filter accordingly.
    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

  4. #4
    cybermonkey is offline Novice
    Windows 10 Office 365
    Join Date
    Jan 2021
    Posts
    16
    That code ends up setting asFilter to equal "[RCA_Number] RCA0003" (depending on which line I double click"
    Then it also prompts to enter parameters, but but still shows no data

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Filter expression created needs to follow syntax of:

    [somefieldname]=somevalue

    And if value is text, need apostrophes:

    [somefieldname]='somevalue'

    or date

    [somefieldname]=#somevalue#

    Review http://allenbrowne.com/ser-62.html
    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.

  6. #6
    cybermonkey is offline Novice
    Windows 10 Office 365
    Join Date
    Jan 2021
    Posts
    16
    Quote Originally Posted by Welshgasman View Post
    Think about it. How is Access meant to know which field you are comparing the value to?
    Just because you clicked on it?
    If you actually wanted to do that, you would have to identify which field it is and set the filter accordingly.
    I understand that, but that is the part I am having issues with in the code.
    Using the code somebody posted in this thread. When double clicking on the field in the first form, it pops up with two prompts, and labeled "RCA_Number" and the second prompt is labeled with the value of the field double clicked.
    If entering nothing at either prompt no data is displayed on the new opened form.
    If entering a value of what was double clicked at both prompts, all the data is shown unfiltered.
    If entering the desired value to filter in the first prompt and nothing in the second prompt; no data shown on the new form.
    If entering nothing at the first prompt and desired filtered value at the second prompt; no data shown on the new form.

  7. #7
    cybermonkey is offline Novice
    Windows 10 Office 365
    Join Date
    Jan 2021
    Posts
    16
    Let me try to explain a bit better in what ultimately id desired.
    There is the list of different RCANumbers. When one is double clicked, then the new form shows all the records that have that value as the RCANumber double clicked, without the need of a pop up prompt.

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,575
    Quote Originally Posted by cybermonkey View Post
    Let me try to explain a bit better in what ultimately id desired.
    There is the list of different RCANumbers. When one is double clicked, then the new form shows all the records that have that value as the RCANumber double clicked, without the need of a pop up prompt.
    Yes, we know what you are trying to do and you have been advised by two different members on how to go about it.
    A filter is
    Which field you are searching on
    The = sign
    What value you are searching for.
    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

  9. #9
    cybermonkey is offline Novice
    Windows 10 Office 365
    Join Date
    Jan 2021
    Posts
    16
    Quote Originally Posted by Welshgasman View Post
    Yes, we know what you are trying to do and you have been advised by two different members on how to go about it.
    A filter is
    Which field you are searching on
    The = sign
    What value you are searching for.
    And unfortunately, what they suggested did not work.

    Below is the code, that was able to make it work.


    Dim RCANum As String
    RCANum = Me.RCA_Number
    DoCmd.OpenForm "Action Items"
    DoCmd.ApplyFilter , "[RCA_Number] = '" & RCANum & "'"

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,575
    Quote Originally Posted by cybermonkey View Post
    And unfortunately, what they suggested did not work.

    Below is the code, that was able to make it work.


    Dim RCANum As String
    RCANum = Me.RCA_Number
    DoCmd.OpenForm "Action Items"
    DoCmd.ApplyFilter , "[RCA_Number] = '" & RCANum & "'"

    what they suggested did not work
    So what do you think this is?

    "[RCA_Number] = '" & RCANum & "'"

    Which field you are searching on [RCA_Number]
    The = sign
    What value you are searching for. RCANum

    That would work equally as well as the filter argument for OpenForm.

    I would always qualify with Me.RCANum
    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

  11. #11
    cybermonkey is offline Novice
    Windows 10 Office 365
    Join Date
    Jan 2021
    Posts
    16
    Quote Originally Posted by Welshgasman View Post
    So what do you think this is?

    "[RCA_Number] = '" & RCANum & "'"

    Which field you are searching on [RCA_Number]
    The = sign
    What value you are searching for. RCANum

    That would work equally as well as the filter argument for OpenForm.

    I would always qualify with Me.RCANum

    What I think this is, is the way I was able to get it to work.
    The code was just not working from the suggestions, not saying anything negative about anybody, but sometimes it is what is. For whatever reason, trying the initial method and suggestions was not working, so started from scratch to approve it slightly differently, and that is the method that was able to do what I needed/wanted it to.

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

Similar Threads

  1. Replies: 20
    Last Post: 10-13-2015, 09:05 AM
  2. Replies: 3
    Last Post: 10-16-2014, 08:49 AM
  3. Replies: 4
    Last Post: 03-10-2014, 12:18 PM
  4. Replies: 7
    Last Post: 05-28-2013, 09:11 AM
  5. Replies: 1
    Last Post: 05-04-2013, 12:19 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