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. - Private Sub Form_Load()
-
Dim rst As DAO.Recordset
-
Dim StrMsgBox As String
-
DoCmd.OpenForm "investmentF"
-
DoCmd.SetWarnings True
-
Set dbs = CurrentDb
-
Set rst = dbs.OpenRecordset("InvestmentF", dbOpenTable)
-
rst.MoveFirst
-
-
Do While Not rst.EOF
-
If Not MaturityDate = Date Then Exit Sub
-
StrMsgBox = MsgBox("An Investment would matured today! Do you want to go to client's Record? ClientName is" & FullName, vbInformation + vbYesNoCancel, "Matured Investment")
-
If StrMsgBox <> vbYes Then Exit Sub
-
DoCmd.OpenForm "InvestmentF"
-
DoCmd.GoToControl "FullName"
-
rs.MoveNext
-
Loop
-
-
MsgBox "Finished searching for Matured investments"
-
-
rs.Close
-
Set rs = Nothing
-
End Sub
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!
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?
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? - Dim dbs As DAO.Database
-
Dim rst As DAO.Recordset
-
Dim strMsg As String
-
Dim strBuild As String
-
-
strMsg = "The following Investments, identified by their IDs, will Mature today: " & _
-
vbCrLf & vbCrLf
-
-
Set dbs = CurrentDb
-
Set rst = dbs.OpenRecordset("InvestmentF", dbOpenTable)
-
-
With rst
-
Do While Not .EOF
-
If ![MaturityDate] = Date Then
-
strBuild = strBuild & ![InvestmentID] & ", "
-
End If
-
rst.MoveNext
-
Loop
-
End With
-
-
'Remove Trailing ", "
-
strBuild = Left$(strBuild, Len(strBuild) - 2)
-
-
MsgBox strMsg & strBuild, vbExclamation, "Matured Investments"
-
-
MsgBox "Finished searching for Matured investments"
-
-
rst.Close
-
Set rst = Nothing
zmbd 5,501
Recognized Expert Moderator Expert
@ADezii - I missed one - opps... (^-^)
Yes, even that single pop-up would be better!
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.
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
Wonderful contribution I would try it as soon as Possible. Thank you very much ADzeli
OK zmbd. It is a good advice.
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?
I figured a way out. I added an error handler to trap this error.
But I must say thank you all for your contribution headache solved!
ADezii 8,834
Recognized Expert Expert 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.
Ok NeoPa can you show me the way the to do this?
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.
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! - Private Sub Form_Load()
-
-
On Error GoTo Err_Handler
-
-
Dim dbs As DAO.Database
-
Dim rst As DAO.Recordset
-
Dim strmsg As String
-
Dim strBuild As String
-
Dim nmaturedinv As Integer
-
Dim iRetValue As Long
-
-
Done = False
-
Label2.Visible = False
-
Label5.Visible = False
-
Set dbs = CurrentDb
-
Set rst = dbs.OpenRecordset("InvestmentCertificateQ")
-
strBuild = ""
-
nmaturedinv = 0
-
With rst
-
Do While Not .EOF
-
If ![MaturityDate] = Date Then
-
nmaturedinv = nmaturedinv + 1
-
List0.AddItem (![FullName]) & ";" & (![AccountNumber]) & ";" & (![CustomerNumber]) & ";" & (![InvestmentCycle]), 0
-
End If
-
rst.MoveNext
-
Loop
-
End With
-
If nmaturedinv = 0 Then
-
Label5.Visible = True
-
List0.AddItem "No investment Is Maturing Today"
-
DoCmd.Close
-
Else
-
Label2.Visible = True
-
iRetValue = sndPlaySound("C:\Program Files (x86)\Falcon\Sounds\Reminder.WAV", SND_ASYNC)
-
End If
-
-
Err_Handler:
-
rst.Close
-
Set rst = Nothing
-
End Sub]
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 :-)
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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
|
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'...
| |
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.
...
|
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 ,
...
|
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...
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |
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...
|
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...
| |