Reflex_ht
Registered User.
- Local time
- Yesterday, 17:07
- Joined
- Sep 11, 2012
- Messages
- 64
Hy,
We are working on a system to have the current vehicle status in our Access DB.
The Idea is that the Drivers send us a Email (over the Navigation system on board) to a specific Email adress. Our DB reads the Inbox of that Emailadress and changes the Status of the Vehicle.
The Emails, for the Status change, have to look like this
$$StatusIDNr,XX##
example:
$$U65,EO##
The StatusIDNr is generated in our DB and send to the Vehicle Navigation System. XX are the two Status codes that can be FE,BE,EO and so one.
All that is alredy done with this two modules:
module (Check_Mail) - it checks if there are mails with Status codes in it and marks the emails without status code as read emails
If there are Unred Emails with status codes in it the second module will run
All that works fine and like it should.
BUT
The Access Application need about 1 sec for 10 Emails to read. When that hapens it blocks the users for that 1 sec and if there are more Emails it blocks the users for more time
The Check_Mail module is runed by a hiden Form every 5 sec.
I know that the String Functions are slowing the Procedure down. Can they me made bether/faster? Is there maby a bether way to do something like this?
Every suggestin is eprisiated
P.S.
When the Email is send from the navigation system it contains also the txt:
Position: "the current position of the vehicle"
Ofcourse we want to use that Data in our DB
We are working on a system to have the current vehicle status in our Access DB.
The Idea is that the Drivers send us a Email (over the Navigation system on board) to a specific Email adress. Our DB reads the Inbox of that Emailadress and changes the Status of the Vehicle.
The Emails, for the Status change, have to look like this
$$StatusIDNr,XX##
example:
$$U65,EO##
The StatusIDNr is generated in our DB and send to the Vehicle Navigation System. XX are the two Status codes that can be FE,BE,EO and so one.
All that is alredy done with this two modules:
module (Check_Mail) - it checks if there are mails with Status codes in it and marks the emails without status code as read emails
Code:
Public Function Check_Mail()
On Error Resume Next
Dim OlApp As Outlook.Application
Dim Inbox As Outlook.MAPIFolder
Dim InboxItems As Outlook.Items
Dim Mailobject As Object
Dim countE As Integer
countE = 0
Set OlApp = CreateObject("Outlook.Application")
Set Inbox = OlApp.GetNamespace("Mapi").GetFolderFromID(DLookup("Status_OO", "tbl_Glob_Var", "[ID]=1"))
Set InboxItems = Inbox.Items
For Each Mailobject In InboxItems
If Mailobject.UnRead Then
If Mailobject.Body Like "*$$*" Then
countE = countE + 1
Else
Mailobject.UnRead = False
End If
End If
Next
If countE <> 0 Then Call mdl_Read_Mail.Read_Mail
End Function
If there are Unred Emails with status codes in it the second module will run
Code:
Public Function Read_Mail()
On Error Resume Next
Dim Styletronic_Nachricht_von_Fahrzeug, Styletronic_Fahrer, Styletronic_Uhrzeit, Styletronic_Position, Styletronic_Nachricht, Styletronic_Status As String
Dim OlApp As Outlook.Application
Dim Inbox As Outlook.MAPIFolder
Dim InboxItems As Outlook.Items
Dim Mailobject As Object
Set OlApp = CreateObject("Outlook.Application")
Set Inbox = OlApp.GetNamespace("Mapi").GetFolderFromID(DLookup("Status_OO", "tbl_Glob_Var", "[ID]=1"))
Set InboxItems = Inbox.Items
For Each Mailobject In InboxItems
If Mailobject.UnRead Then
Nachricht = Mailobject.Body
Erstellt = Mailobject.CreationTime
'If InStrRev(Nachricht, "Uhrzeit:") > 0 Then
'Styletronic_Uhrzeit = Nz(Replace(Mid(Nachricht, InStrRev(Nachricht, "Uhrzeit:") + 8, InStrRev(Nachricht, "Position:") - InStrRev(Nachricht, "Uhrzeit:") - 8), Chr(13), ""), "")
'Else
Styletronic_Uhrzeit = Erstellt
'End If
If InStrRev(Nachricht, "Position:") > 0 Then
Styletronic_Position = Replace(Nz(Trim(Mid(Nachricht, InStrRev(Nachricht, "Position:") + 9, InStrRev(Nachricht, "Nachricht:") - InStrRev(Nachricht, "Position:") - 9)), "nicht angegeben"), Chr(13), "")
Else
Styletronic_Position = "Unknown Location"
End If
Styletronic_Status = Replace(Nz(Trim(Mid(Nachricht, InStrRev(Nachricht, "$$") + 2, InStrRev(Nachricht, "##") - InStrRev(Nachricht, "$$") - 2)), "X"), Chr(13), "")
styletronic_ID = Trim(Mid(Left(Styletronic_Status, InStr(Styletronic_Status, ",") - 1), 2))
Styletronic_Liste = Left(Styletronic_Status, 1)
Styletronic_FULL_EMPTY = Nz(Left(Right(Styletronic_Status, 2), 1), "X")
Styletronic_IN_OUT_BEGIN_END = Nz(Right(Right(Styletronic_Status, 2), 1), "X")
If DCount("STATUS_ID", "qry_Status_" & Styletronic_Liste & " , [STATUS_ID] like '*" & styletronic_ID & "*'") <> 0 Then
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE qry_Status_" & Styletronic_Liste & " SET [IN_OUT_BEGIN_END]='" & Styletronic_IN_OUT_BEGIN_END & "', [FULL_EMPTY]='" & Styletronic_FULL_EMPTY & "' , [DATE_TIME]='" & Styletronic_Uhrzeit & "' , [PLACE_OF_EVENT]='" & Styletronic_Position & "' WHERE [STATUS_ID]='" & styletronic_ID & "' ;"
DoCmd.SetWarnings True
End If
Styletronic_Position = ""
Styletronic_Nachricht = ""
Styletronic_Status = ""
Styletronic_ID = ""
Styletronic_Liste = ""
Styaletronic_IN_OUT_BEGIN_END = ""
Styletronic_FULL_EMPTY = ""
Mailobject.UnRead = False
End If
Next
'Call mdl_Status_Export.Status_Export
End Function
All that works fine and like it should.
BUT
The Access Application need about 1 sec for 10 Emails to read. When that hapens it blocks the users for that 1 sec and if there are more Emails it blocks the users for more time
The Check_Mail module is runed by a hiden Form every 5 sec.
I know that the String Functions are slowing the Procedure down. Can they me made bether/faster? Is there maby a bether way to do something like this?
Every suggestin is eprisiated
P.S.
When the Email is send from the navigation system it contains also the txt:
Position: "the current position of the vehicle"
Ofcourse we want to use that Data in our DB