hardik_088
Registered User.
- Local time
- Today, 09:54
- Joined
- May 31, 2011
- Messages
- 82
Hi guys,
I have created automatic email like when quantity is less than three in my database for some items then it will send automatic email. and there is a fixed email address it will send there only. but i am thinking that suppose administator have change his/her email address and now he/she want that automatic email there on new email address .so how she can change or add more email address in database because code will be locked.
So how can i make that facility.
--------------------------------
here is my code for in timer that will check data after every hour
Private Sub Form_Timer()
CheckOrderLevels "Laptops", "[Part number]", "[quantity ordered]", "Laptops"
Me.TimerInterval = 3600000
End Sub
--------------------------------------------
code for automatic email
Private Sub CheckOrderLevels(ByVal strTable As String, ByVal strNameField As String, ByVal strQuantityField As String, ByVal strProduct As String)
On Error Resume Next
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT " & strNameField & " FROM " & strTable _
& " WHERE " & strQuantityField & " < 3", dbOpenSnapshot)
With rs
If .RecordCount > 0 Then
Dim sProducts As String
Dim bFirst As Boolean
sProducts = ""
bFirst = True
.MoveFirst
Do While Not .EOF
If Not bFirst Then sProducts = sProducts & vbCrLf
sProducts = .Fields(strNameField)
bFirst = False
.MoveNext
Loop
SendReport strTable, strProduct, sProducts
End If
.Close
End With
End Sub
Private Sub SendReport(ByVal strTable As String, ByVal strProduct As String, ByVal sProducts As String)
On Error Resume Next
Dim olApp As Object
Dim objMail As Object
Set olApp = GetObject(, "Outlook.Application")
If Err Then Set olApp = CreateObject("Outlook.Application")
Set objMail = olApp.CreateItem(olMailItem)
With objMail
.BodyFormat = olFormatHTML
.To = "test@somewhere.com"
.Subject = "Automated message: " & strProduct & " Requires Ordering"
.HTMLBody = "There is less than three items (Part Number is : " & sProducts & ") in " & strTable & " table"
.Send
End With
End Sub
I have created automatic email like when quantity is less than three in my database for some items then it will send automatic email. and there is a fixed email address it will send there only. but i am thinking that suppose administator have change his/her email address and now he/she want that automatic email there on new email address .so how she can change or add more email address in database because code will be locked.
So how can i make that facility.
--------------------------------
here is my code for in timer that will check data after every hour
Private Sub Form_Timer()
CheckOrderLevels "Laptops", "[Part number]", "[quantity ordered]", "Laptops"
Me.TimerInterval = 3600000
End Sub
--------------------------------------------
code for automatic email
Private Sub CheckOrderLevels(ByVal strTable As String, ByVal strNameField As String, ByVal strQuantityField As String, ByVal strProduct As String)
On Error Resume Next
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT " & strNameField & " FROM " & strTable _
& " WHERE " & strQuantityField & " < 3", dbOpenSnapshot)
With rs
If .RecordCount > 0 Then
Dim sProducts As String
Dim bFirst As Boolean
sProducts = ""
bFirst = True
.MoveFirst
Do While Not .EOF
If Not bFirst Then sProducts = sProducts & vbCrLf
sProducts = .Fields(strNameField)
bFirst = False
.MoveNext
Loop
SendReport strTable, strProduct, sProducts
End If
.Close
End With
End Sub
Private Sub SendReport(ByVal strTable As String, ByVal strProduct As String, ByVal sProducts As String)
On Error Resume Next
Dim olApp As Object
Dim objMail As Object
Set olApp = GetObject(, "Outlook.Application")
If Err Then Set olApp = CreateObject("Outlook.Application")
Set objMail = olApp.CreateItem(olMailItem)
With objMail
.BodyFormat = olFormatHTML
.To = "test@somewhere.com"
.Subject = "Automated message: " & strProduct & " Requires Ordering"
.HTMLBody = "There is less than three items (Part Number is : " & sProducts & ") in " & strTable & " table"
.Send
End With
End Sub
Last edited: