Page 1 of 2 12 LastLast
Results 1 to 15 of 30
  1. #1
    ScubaBart is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jul 2024
    Posts
    117

    Attempting to use vba to find earliest date in a record-set (not from query)

    Making progress on the Bee application



    So, working on the Inspection Log form(s) and attempting to filter for various criteria to show only the desired results on the main Inspection Form.

    The filters I want to use are 1) By Apiary 2) Beginning Inspection Date and 3) Ending Inspection Date

    I have the Apiary part of the filtering working by itself no problem and I think once I understand how the date filtering works, I can integrate it.

    The main form opens with the Apiary filter set to All Apiaries and the End Date as the current date. I want to be able to populate the Begin Date with the actual date from the earliest inspection record AND I need that date value to update if I modify the Apiary filter as different Apiaries will have different inspection dates.

    For the initial Begin Date value, I am hoping there is a simple vb function that will search a defined set of records for the earliest date in the Date field.

    For updating, the value would have to search that field in a subset of the records as defined by the value of the Apiary filter. No other filter criteria will be applied.

    I have searched and everything seems to point to queries and I can't really find anything that is just vba.

    Will I have to use a query for this or can I do it relatively simply in vb ?

    Once I know for sure which way I have to go and some of the basic syntax I can hopefully bumble my way through it.

    If it turns complicated, I can upload my app so my approach is more easily seen.

    Thanks !!

    Just discovered that I do indeed have one additional criteria and that is that the records need to show only for Active Hives and Apiaries.

    Going to do a little cleanup on the forms and such and upload the current version later.
    Last edited by ScubaBart; 03-24-2025 at 03:26 PM. Reason: Added information

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Could use a recordset but really, pulling a single value from dataset is what domain aggregate functions are for.

    What do you mean by "update" - if you just want the calculation to be dynamic based on some criteria, that is certainly possible.

    https://rogersaccessblog.blogspot.co...mystified.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.

  3. #3
    ScubaBart is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jul 2024
    Posts
    117
    Quote Originally Posted by June7 View Post
    Could use a recordset but really, pulling a single value from dataset is what domain aggregate functions are for.

    What do you mean by "update" - if you just want the calculation to be dynamic based on some criteria, that is certainly possible.
    I am updating my original post since as I am working on this, I discovered there is one other criteria that has to be applied and that is that the Apiaries must be tagged as Active. That way I don't show inspections from inactive apiaries. That particular criteria will be a constant

    But, to your comments, the filtering is not intended to show a single result but rather a narrowed down set of records from the full list.

    And yes, by update, I am wanting the results to update in real time as I adjust the criteria.

    Looked at the link you posted but don't think that is going to accomplish what I am looking for.

    I think I will need to format a few things in my forms and upload the app for it to make more sense.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,552
    You use whatever you need to check as criteria in the domain function.
    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

  5. #5
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    What exactly do you want to update? Just describe the high level in simple English.
    Can you give us an example, say with By Apiary?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Quote Originally Posted by ScubaBart View Post
    For the initial Begin Date value, I am hoping there is a simple vb function that will search a defined set of records for the earliest date in the Date field.
    This indicates you want just a single value - domain aggregate function can accomplish that.
    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
    ScubaBart is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jul 2024
    Posts
    117
    I may have made this request confusing by trying to do two different though semi-related things.

    I have downloaded the sample search database by Allen Browne and am looking it over and after a brief initial review, I think I will indeed be able to use this approach for my dynamic search function. While his example is set up to set the criteria then apply the resulting filter, I expect I can use the 'AfterUpdate' event to run the filter dynamically after any given change in the applicable fields.


    I am also changing my approach for setting the begin date to the earliest date form the underlying table. I am going to do this only when the form is initially loaded and not try to update it to the earliest date after each change in the Apiary selection filter.

    The above comment(s) suggest using the domain aggregate function. I am not familiar with that but will research it and with luck, figure it out. If not, I'll be back.......



    Thanks !!

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Allen Browne's example provides user with button to trigger search. Yes, could trigger search after input into a control. This would most likely use AfterUpdate event calling the search procedure. This requires control to lose focus either with tab or enter or click.
    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.

  9. #9
    ScubaBart is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jul 2024
    Posts
    117
    ok, a semi-related issue here. The filter process seems to be working except for one part.

    I am using the DLookup function to set the value in a checkbox. Took a while but I got that to work fine. Problem is, when I try to use the value of that checkbox for the filter, it does not work.

    I even tried to use just that single part of the filter by itself. I can set the criteria of the filter based on the value of the checkbox (continuous forms) but when I set FilterOn to true, it bugs out but gives no reason.

    Is there a limitation that I am not aware of where I can't use the value obtained by a DLookup for a search criteria ?

    This seems to be my final stumbling block for the filter operation.

    Actually, one more piece of info, When I try to activate the filter with just that one criteria, it asks me to enter the parameter value as if it wasn't provided.

  10. #10
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    564
    I'd do this by building my filter string in code and then applying it somewhere (like in the Open event of a form or report).

  11. #11
    ScubaBart is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jul 2024
    Posts
    117
    Building the filter with all the other criteria works and I am updating the filter when I change any of the conditions (in combo or unbound fields).

    The problem is, is seems to not accept the value of the checkbox where I am using the DLookUp function.

  12. #12
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,552
    Is there a limitation that I am not aware of where I can't use the value obtained by a DLookup for a search criteria ?
    No, at least not that I am aware of.


    Actually, one more piece of info, When I try to activate the filter with just that one criteria, it asks me to enter the parameter value as if it wasn't provided.
    That indicates it cannot find that criteria, so check your spelling and even check the value.

    Start using Debug.Print to check you have what you think you have. i believe I have said this to you before?
    Walk your code with F8 and breakpoints and examine what you actually have, not what you think you have.

    See the Debugging link in my signature on how to do this, if you do not know.
    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

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Does sound like a spelling error.

    I have no problem pulling value from checkbox set with DLookup() expression.
    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.

  14. #14
    ScubaBart is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jul 2024
    Posts
    117
    Quote Originally Posted by Welshgasman View Post

    That indicates it cannot find that criteria, so check your spelling and even check the value.

    Start using Debug.Print to check you have what you think you have. i believe I have said this to you before?
    Walk your code with F8 and breakpoints and examine what you actually have, not what you think you have.

    See the Debugging link in my signature on how to do this, if you do not know.

    I have run into the spelling error before and checked, rechecked, entered, re-entered, copied and pasted the Name of the checkbox at least a dozen times.

    This is the filter code
    Code:
    Private Sub Filter_Button_Click()
    
    Me.Filter = "Apiary_Active_LkUp = -1"
    Me.FilterOn = True
    
    
    End Sub
    This is the checkbox
    Click image for larger version. 

Name:	Screen Shot 03-27-25 at 09.00 PM.PNG 
Views:	16 
Size:	17.9 KB 
ID:	52885

    I did a step through on the debugging as you have suggested. I did learn that from you from before.

    When it steps into the Me.Filter line, that's when this popup shows up asking for the value.
    Click image for larger version. 

Name:	Screen Shot 03-27-25 at 09.02 PM.PNG 
Views:	16 
Size:	13.4 KB 
ID:	52886

    I can enter a value manually and it works but that kind of defeats the purpose.

    If I can't figure it out by tomorrow, I'll upload a copy of the file.

    Thanks for trying to help.....

  15. #15
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,552
    You need to check the source field, NOT the form control.
    What is Apiary_Active_LkUp mapped to, what is it's control source.

    Could also try True instead of -1 ?
    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

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 11
    Last Post: 07-16-2016, 11:38 AM
  2. Replies: 4
    Last Post: 02-25-2016, 08:18 AM
  3. Replies: 4
    Last Post: 12-16-2014, 05:08 PM
  4. Replies: 3
    Last Post: 04-19-2013, 12:49 PM
  5. Replies: 1
    Last Post: 02-17-2012, 04:43 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