473,513 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Loop though records and display pop up message if a date Criteria is met

46 New Member
I have a form called InvestmentF based on a table InvestmentF with the following fields

Investor Name
InvestorID
InvestmentDate
MaturityDate

What I want to is that on load, Access should look through the recordsets and check for Investments which would mature on the MaturityDate and display a continuous pop Message for all matured investments

I guess Do loop would help but cannot really figure out how to go about it.
This is the code I have so far but it just open the form and does nothing!

I would appreciate if there is another way to do this.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. Dim rst As DAO.Recordset
  3. Dim StrMsgBox As String
  4. DoCmd.OpenForm "investmentF"
  5. DoCmd.SetWarnings True
  6. Set dbs = CurrentDb
  7. Set rst = dbs.OpenRecordset("InvestmentF", dbOpenTable)
  8. rst.MoveFirst
  9.  
  10. Do While Not rst.EOF
  11. If Not MaturityDate = Date Then Exit Sub
  12. StrMsgBox = MsgBox("An Investment would matured today! Do you want to go to client's Record? ClientName is" & FullName, vbInformation + vbYesNoCancel, "Matured Investment")
  13. If StrMsgBox <> vbYes Then Exit Sub
  14. DoCmd.OpenForm "InvestmentF"
  15. DoCmd.GoToControl "FullName"
  16. rs.MoveNext
  17. Loop
  18.  
  19. MsgBox "Finished searching for Matured investments"
  20.  
  21. rs.Close
  22. Set rs = Nothing
  23. End Sub
Sep 20 '13 #1
17 2595
zmbd
5,501 Recognized Expert Moderator Expert
Before we go down this route...
What you suggest doing is not considered to be the most user friendly for more than one or two such messages.

As an end user, if the programmer stuffed a dozen pop-up prompts in my face, I'd be highly irrate by about the fourth such message. I'd be leading the pitch-fork and tourch mob by the time anything more than that popped up.

I would highly recommend that you reconsider the design of your form:

Have a form that has a combobox that allows you to select matured, unmatured, and all. The form's filter and control default could be set to show the matured records on load

(These insight articles should provide some guidence here:
- Microsoft Access / VBA Insights Sitemap
.Cascaded Form Filtering
.Multiple Combobox Filter with Clear Option
.Example Filtering on a Form.


OR

- perhaps to use conditional formating
Change the appearance of a control by using conditional formatting (ACC2007/2010) using the maturity of the record for the comparision values.

OR

Perhaps an unbound parent form that has two subforms. One subform based on a query that pulls the records that have not yet matured and the second subform based on a query where the records that have matured.

IF you truely insist on the pop-ups, then what I would do is either use stored query or open a recordset in the vba that pulls these records. Check that the record set has records in it. Move to the first record. Then use a do..while..not EOF loop and pop-up the message with the information from the record that you want... just don't come to me when the Mob is outside your office!
Sep 20 '13 #2
yashuaking
46 New Member
Ok I got your point. But it was a request made by those am developing the database for. They want Pop ups. Can you please elaborate on how to use the do while loop for me to generate the pop up?
Sep 25 '13 #3
ADezii
8,834 Recognized Expert Expert
If you insist on this approach, why not display a single Pop Up Dialog displaying all Invesments, via their IDs, that will mature on the Current Date?
Expand|Select|Wrap|Line Numbers
  1. Dim dbs As DAO.Database
  2. Dim rst As DAO.Recordset
  3. Dim strMsg As String
  4. Dim strBuild As String
  5.  
  6. strMsg = "The following Investments, identified by their IDs, will Mature today: " & _
  7.           vbCrLf & vbCrLf
  8.  
  9. Set dbs = CurrentDb
  10. Set rst = dbs.OpenRecordset("InvestmentF", dbOpenTable)
  11.  
  12. With rst
  13.   Do While Not .EOF
  14.     If ![MaturityDate] = Date Then
  15.       strBuild = strBuild & ![InvestmentID] & ", "
  16.     End If
  17.       rst.MoveNext
  18.   Loop
  19. End With
  20.  
  21. 'Remove Trailing ", "
  22. strBuild = Left$(strBuild, Len(strBuild) - 2)
  23.  
  24. MsgBox strMsg & strBuild, vbExclamation, "Matured Investments"
  25.  
  26. MsgBox "Finished searching for Matured investments"
  27.  
  28. rst.Close
  29. Set rst = Nothing
Sep 25 '13 #4
zmbd
5,501 Recognized Expert Moderator Expert
@ADezii - I missed one - opps... (^-^)

Yes, even that single pop-up would be better!
Sep 25 '13 #5
ADezii
8,834 Recognized Expert Expert
The only disadvantage, should you decide to disply more than the Investment IDs, is that you may go over the Maximum Allowable Characters in the Message Box, and the Build String may be concatenated.
Sep 25 '13 #6
zmbd
5,501 Recognized Expert Moderator Expert
Yashuaking:
Even though the customer asked for this... you really should go back to them with the alternatives... point out to them that as they grow that there is a high potential for dozens if not hundreds of records, and the corresponding pop-ups! The end user will simply press and hold down the [Enter]-key; thus, bypassing the intent of the pop-up
Sep 25 '13 #7
yashuaking
46 New Member
Wonderful contribution I would try it as soon as Possible. Thank you very much ADzeli
Sep 25 '13 #8
yashuaking
46 New Member
OK zmbd. It is a good advice.
Sep 25 '13 #9
yashuaking
46 New Member
Adzeli's code works perfectly for matured investments but there was a little problem. When no investment is maturing today, it gives a vb error message that run-time error 5, invalid procedure call or argument. Please can you help me sort this out?
Oct 11 '13 #10
yashuaking
46 New Member
I figured a way out. I added an error handler to trap this error.
Oct 11 '13 #11
yashuaking
46 New Member
But I must say thank you all for your contribution headache solved!
Oct 11 '13 #12
ADezii
8,834 Recognized Expert Expert
You are quite welcome.
Oct 11 '13 #13
NeoPa
32,557 Recognized Expert Moderator MVP
A faster way to arrive at your list of 'qualifying' records is to include the criteria in the dataset that you open. The code wouldn't change too much, but the logic would be that it is no longer necessary to check the status of each record as that has already been done for you (and much faster generally) by the SQL.

Just a thought. The existing solutions posted are not invalidated in any way by incorporating this.
Oct 13 '13 #14
yashuaking
46 New Member
Ok NeoPa can you show me the way the to do this?
Oct 14 '13 #15
zmbd
5,501 Recognized Expert Moderator Expert
yashuaking
Instead of just opening the recordset on the raw data table as done here:
Set rst = dbs.OpenRecordset("InvestmentF", dbOpenTable)

Build the query first to return only the records of interest. Then use this query as the source
Set rst = dbs.OpenRecordset("qry_withwhatyouwant", dbOpenDynaset)

You can even do this in code by building the SQL string (If I do this in the VBA code, quite often, I cheat and use the query builder and switch to SQL view and copy and paste the SQL into the code, with minimal modification it's usable) and assigning that instead of the table or query name
strSQL = "SELECT [field] FROM tbl_example WHERE( conditions )
Set rst = dbs.OpenRecordset(strSQL, dbOpenDynaset)

The rest should be straight forward.
Oct 14 '13 #16
yashuaking
46 New Member
I modified the code and am using list box instead of a message box to populate more entries this is the new code I wrote. I EVEN ADDED a sound alert to it-Thanks to NeoPa's tutorial on sound!
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3.     On Error GoTo Err_Handler
  4.  
  5.     Dim dbs As DAO.Database
  6.     Dim rst As DAO.Recordset
  7.     Dim strmsg As String
  8.     Dim strBuild As String
  9.     Dim nmaturedinv As Integer
  10.     Dim iRetValue As Long
  11.  
  12.     Done = False
  13.     Label2.Visible = False
  14.     Label5.Visible = False
  15.     Set dbs = CurrentDb
  16.     Set rst = dbs.OpenRecordset("InvestmentCertificateQ")
  17.     strBuild = ""
  18.     nmaturedinv = 0
  19.     With rst
  20.         Do While Not .EOF
  21.             If ![MaturityDate] = Date Then
  22.                 nmaturedinv = nmaturedinv + 1
  23.                 List0.AddItem (![FullName]) & ";" & (![AccountNumber]) & ";" & (![CustomerNumber]) & ";" & (![InvestmentCycle]), 0
  24.             End If
  25.             rst.MoveNext
  26.         Loop
  27.     End With
  28.     If nmaturedinv = 0 Then
  29.         Label5.Visible = True
  30.         List0.AddItem "No investment Is Maturing Today"
  31.         DoCmd.Close
  32.     Else
  33.         Label2.Visible = True
  34.         iRetValue = sndPlaySound("C:\Program Files (x86)\Falcon\Sounds\Reminder.WAV", SND_ASYNC)
  35.     End If
  36.  
  37. Err_Handler:
  38.     rst.Close
  39.     Set rst = Nothing
  40. End Sub]
Oct 23 '13 #17
NeoPa
32,557 Recognized Expert Moderator MVP
I don't believe that was one of mine, but I'm nevertheless pleased you found it helpful, and pleased you're happy with your results :-)
Oct 24 '13 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

11
4203
by: David B | last post by:
I have 2 querys with the following in the date criteria Between DateAdd("m",-6,(!!)) And (!!) Between DateAdd("m",-24,(!!)) And DateAdd("m",-6,(!!)) Problem is they both look at the same...
4
1648
by: gregork | last post by:
I have a query to return records within a date range. I have a prompt to enter a start and end date which works fine as long as I enter the date in mm/dd/yy format (even though the date field is in...
4
3460
by: Ryan Liu | last post by:
How to loop though controls on the form? I set each control's TabStop and TabIndex, but at run time, I press Tab key, it jump though first control to last control and does not go back to the...
1
1876
by: mkmkmkmk | last post by:
Hi, I've a table with fields name, date of format(hr:min:sec month day, year) I'm in search of a query that displays records group by records of same date. Please help
7
1929
by: iahamed via WebmasterKB.com | last post by:
Hi all, I need to display records Horizontally, I do not know for some reason this code gives me an error, uses an access db. Microsoft VBScript compilation (0x800A040E) 'loop' without 'do'...
0
1545
by: zeusspandex | last post by:
Im creating a cross tab query which sorts via and sums the for each type of . I want to be able to add a date criteria, so the user can specify that the query processes data between two dates. ...
1
1557
by: zeusspandex | last post by:
Hi, i have the following SQL query and would like to add date criteria to it. the field being from the table and the criteria being Between !! And !! query: SELECT , ...
21
11075
by: mukeshrasm | last post by:
Hi I am deleting records from database using checkbox. means only that record will be deleted from database which are selected in checkbox. and before deleting record I am displaying a message...
5
4821
by: sh55555 | last post by:
I have built a query in Access using the DateSerial function to convert dates such as 20100401 to 04/01/2010. The query results work fine and the date is displayed correctly. I am now trying to...
9
6213
by: Raza Zahur | last post by:
Hi all, I've googled and googled but I can google no more, so I am here to ask for help on an issue I am having. I have a macro that runs a series of queries. Before the macro can be run, the...
0
7265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7171
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7545
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7539
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5692
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5095
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4751
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3240
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
461
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.