Syspro - Update query for sales prices - sql

I can't seem to find any information on SQL scripts for Syspro - Google searches just come up with 3rd party software despite Syspro using a fairly standard looking SQL database.
I'm just wondering if anyone on here has any experience with updating Syspro via SQL updates - I have a client that uses Syspro and they've previously updated it by exporting everything into Access, making changes and updating everything from there - I was told by their out-going IT consultant that this is the only way to update Syspro (which, I suspect, isn't true).
Just looking for some do's and dont's before I go screwing up data!
thanks,
Darren

It's not advisable to update the SYSPRO database directly. While it is relatively simple to breakdown and track what data is stored where etc. there is more often than not more than 1 place where a field is updated and/or there is an additional flag that is also changed. Further, updating it directly in the database would also get rid of any possible audit trail.
If this needs to be done in bulk (as your question seems to refer) then this would be best done by posting an update using one of the SYSPRO "business objects". Have a look here for more info regarding business objects: SYSPRO Business Object Library
There are 2 ways you can make use of this: in a custom pane within SYSPRO (no licensing requirements then) or if your customer is licensed for the respective business object you could write an external program to post updates using the business object.
Below is a custom pane I created sometime ago that updates prices of items based on an excel spreadsheet. Save the below code section into a txt file and when in SYSPRO if you click on the drop down arrow (on the top right of any pane) you can select Customized Pane > Import Customized Pane and specify this txt file you have saved. This will create the custom pane with title Pricelist Import. If you now press the refresh button on this customized pane it's going to ask you for an excel file to base it's update on. By default it will look for a file called Pricelist Import.xlsx in the SYSPRO\Base\Settings folder of the machine you are working on. You will need to create a spreadsheet with 5 columns and in this order too (StockCode, PriceCode, SellingPrice, PriceBasis, CommisionCode). Once you have a spreadsheet and specify the file at this prompt it will load the contents of the spreadsheet into the listview and by default all entries will be selected to import. If you now press Update it will update the prices accordingly and if not possible will return the respective error messages back into the listview.
# Customized Panes for 'IMPDH2LZ' Created: 2013/09/17
# PANE:Pricelist Import
[PANE]
CHRISVIMPDH2LZ 01000Pricelist Import 020 000000500001IMPDH2000M000Update 3362 00000 0
[VBSCRIPT]
' This script contains functions for customized pane events.
' You must not modify the name of the functions.
Option Explicit
Public Debug : Debug = "False"
Function CustomizedPane_OnRefresh()
Dim ImportFilePmt : ImportFilePmt = InputBox("Enter Location of Excel file to Import?", "Pricelist Import File", SystemVariables.CodeObject.baseSettingsFolder &"Pricelist Import.xlsx")
Dim objExcel : Set objExcel = CreateObject("Excel.Application")
On error resume next
Dim objWorkbook : Set objWorkbook = objExcel.Workbooks.Open(ImportFilePmt)
If err then
If ImportFilePmt <> "" then
msgbox "Error Importing File: " & vbcrlf & err.Description & vbCrlf & vbCrlf & "Import Cancelled!!", vbCritical, "Error Importing/Opening File"
Exit Function
Else
CustomizedPane_OnLoad
Exit Function
End If
End if
on error Goto 0
Dim objWorksheet : Set objWorksheet = objExcel.Worksheets(1)
objWorksheet.Activate
Dim intRow : intRow = 2
Dim XMLForList
Dim intLinesRow : intLinesRow = 2
XMLForList = "<ImportList>"
Do Until objExcel.Cells(intLinesRow,1).Value = "" or objExcel.Cells(intLinesRow,1).Value = " "
XMLForList = XMLForList & "<Item><StockCode>"& objExcel.Cells(intLinesRow, 1).Value &"</StockCode>"
XMLForList = XMLForList & "<PriceCode>" & objExcel.Cells(intLinesRow,2).Value & "</PriceCode>"
XMLForList = XMLForList & "<SellingPrice>" & objExcel.Cells(intLinesRow,3).Value & "</SellingPrice>"
XMLForList = XMLForList & "<PriceBasis>" & objExcel.Cells(intLinesRow,4).Value & "</PriceBasis>"
XMLForList = XMLForList & "<CommisionCode>" & objExcel.Cells(intLinesRow,5).Value & "</CommisionCode>"
XMLForList = XMLForList & "<Import>1</Import>"
XMLForList = XMLForList & "</Item>"
intLinesRow = intLinesRow + 1
Loop
XMLForList = XMLForList & "</ImportList>"
objExcel.Quit
Dim ListXML
ListXML = ListXML & "<Columns PrimaryNode='Item' Style='DataGrid' AutoSize='true' FreezeColumn='0' >"
ListXML = ListXML & "<Column Name='StockCode' Description='Stock code' />"
ListXML = ListXML & "<Column Name='PriceCode' Description='Price code' />"
ListXML = ListXML & "<Column Name='SellingPrice' Description='Selling price' Type='Numeric' Alignment='Right' HdrAlignment='Right' Decimals='2' />"
ListXML = ListXML & "<Column Name='PriceBasis' Description='Price basis' />"
ListXML = ListXML & "<Column Name='CommisionCode' Description='Commision code' />"
ListXML = ListXML & "<Column Name='Import' Description='Import' Type='checkbox' Editable='true' />"
ListXML = ListXML & "</Columns>"
CustomizedPane.CodeObject.ListviewProperties = ListXML
CustomizedPane.CodeObject.ListviewData = XMLForList
msgbox intLinesRow - 2 & " record/s read",vbInformation,"File Imported"
End Function
Function FileHandle(Action, ActVariable)
Dim Path : Path = SystemVariables.CodeObject.baseSettingsFolder & "ExcelImportPanePath.txt"
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
dim fso, ts
Set fso = CreateObject("Scripting.FileSystemObject")
If Action = "WritePath" then
Set ts = fso.CreateTextFile(Path,2,False)
ts.Write (ActVariable)
ts.Close
Elseif Action = "DeletePath" then
Set ts = fso.OpenTextFile(Path,1)
Dim FilePathDP : FilePathDP = ts.ReadAll
ts.Close
fso.DeleteFile FilePathDP
Elseif Action = "ReadPath" then
on error Resume Next
Set ts = fso.OpenTextFile(Path,ForReading)
Dim strLine
Do Until ts.AtEndOfStream
strLine = ts.ReadLine
Loop
ts.close
if Err then
FileHandle = "File Deleted"
Else
FileHandle = strLine
End if
On Error Goto 0
Elseif Action = "Delete" then
On Error Resume Next
fso.DeleteFile Path
If err then
Exit Function
End if
On Error Goto 0
End if
End Function
Function CustomizedPane_OnLoad()
Dim ListXML
ListXML = ListXML & "<Columns PrimaryNode='Notify' Style='DataGrid' AutoSize='true' FreezeColumn='0' >"
ListXML = ListXML & "<Column Name='Note' Description='NOTE' />"
ListXML = ListXML & "</Columns>"
CustomizedPane.CodeObject.ListviewProperties = ListXML
Dim ShowNote
ShowNote = "<Start>"
ShowNote = ShowNote & "<Notify><Note>First Load the Excel File Path...</Note></Notify>"
ShowNote = ShowNote & "</Start>"
CustomizedPane.CodeObject.ListviewData = ShowNote
End Function
Function CustomizedPane_OnToolbarButton1Clicked()
Dim MaxRows : MaxRows = Ubound(CustomizedPane.CodeObject.Array, 2)
If MaxRows = 0 OR CustomizedPane.CodeObject.Array(0,0) = "First Load the Excel File Path..." then
Exit Function
Else
Dim Counter
Dim CLineCounter : CLineCounter = 0
For Counter = 0 to MaxRows - 1
If CustomizedPane.CodeObject.Array(5, Counter) = "1" then
CLineCounter = CLineCounter + 1
End If
Next
If CLineCounter = 0 then
msgbox "There was nothing selected to import.",vbInformation,"Importing..."
Exit Function
Else
msgbox CLineCounter & " record/s to be updated.",vbInformation,"Importing..."
CallINVSPR
End If
End If
End Function
Function CallINVSPR()
dim XMLOut, XMLParam, XMLDoc
XMLParam = "<SetupInvPrice>"
XMLParam = XMLParam & " <Parameters>"
XMLParam = XMLParam & " <IgnoreWarnings>N</IgnoreWarnings>"
XMLParam = XMLParam & " <ApplyIfEntireDocumentValid>Y</ApplyIfEntireDocumentValid>"
XMLParam = XMLParam & " <ValidateOnly>N</ValidateOnly>"
XMLParam = XMLParam & " </Parameters>"
XMLParam = XMLParam & "</SetupInvPrice>"
XMLDoc = " <SetupInvPrice>"
Dim MaxRows : MaxRows = Ubound(CustomizedPane.CodeObject.Array, 2)
Dim Counter
Dim LineCounter : LineCounter = 0
Dim CLineCounter : CLineCounter = 0
For Counter = 0 to MaxRows - 1
If CustomizedPane.CodeObject.Array(5, Counter) = "1" then
XMLDoc = XMLDoc & " <Item>"
XMLDoc = XMLDoc & " <Key>"
XMLDoc = XMLDoc & " <StockCode>" & CustomizedPane.CodeObject.Array(0, Counter) & "</StockCode>"
XMLDoc = XMLDoc & " <PriceCode>" & CustomizedPane.CodeObject.Array(1, Counter) & "</PriceCode>"
XMLDoc = XMLDoc & " </Key>"
XMLDoc = XMLDoc & " <SellingPrice>" & CustomizedPane.CodeObject.Array(2, Counter) & "</SellingPrice>"
XMLDoc = XMLDoc & " <PriceBasis>" & CustomizedPane.CodeObject.Array(3, Counter) & "</PriceBasis>"
XMLDoc = XMLDoc & " <CommissionCode>" & CustomizedPane.CodeObject.Array(4, Counter) & "</CommissionCode>"
XMLDoc = XMLDoc & " </Item>"
CLineCounter = CLineCounter + 1
End If
Next
XMLDoc = XMLDoc & " </SetupInvPrice>"
on error resume next
XMLOut = CallSetup("INVSPR",XMLParam,XMLDoc,"Update","auto")
if err then
msgbox err.Description, vBCritical, "Calling Business Object"
exit function
end if
' Switch on error handling
on error goto 0
'msgbox CLineCounter & " rows updated"
If Debug = "True" then
Dim Path : Path = SystemVariables.CodeObject.baseSettingsFolder & "DEBUGExcelImportPane.txt"
'Output XML to file
dim fso, ts
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile(Path,2,True)
ts.Write ("XMLIn:" & vbCrlf & XMLDoc & vbCrlf &"XMLParam:" & vbCrlf & XMLParam & vbCrlf &"XMLOut:" & vbCrlf & XMLOut)
ts.Close
msgbox "Debug Done." & vbCrLf & " Check: "& Path
End If
ResultValidate XMLOut, "Update", CLineCounter
End Function
Function ResultValidate(XMLIn, Action, CLineCounter)
Dim XMLDOM : Set XMLDOM = CreateObject("Microsoft.XMLDOM")
XMLDOM.Async = False
XMLDOM.LoadXML(XMLIn)
Dim ListXML
Dim WarningMsgs : Set WarningMsgs = XMLDOM.GetElementsByTagName("ErrorDescription")
Dim StkList
If WarningMsgs.Length > 0 then
StkList = "<List>"
StkList = StkList & "<StockList>"
StkList = StkList & "<Notes>Errors Found: " & WarningMsgs.Length & "</Notes>"
StkList = StkList & "</StockList>"
If WarningMsgs.Length > 0 then
Dim WarnItems
For Each WarnItems in WarningMsgs
StkList = StkList & "<StockList>"
StkList = StkList & "<Notes>Error in : " & WarnItems.ParentNode.NodeName & " - " & WarnItems.PreviousSibling.PreviousSibling.Text & ": " & WarnItems.Text &"</Notes>"
StkList = StkList & "</StockList>"
Next
End If
StkList = StkList & "</List>"
ListXML = "<Columns PrimaryNode='StockList' Style='DataGrid' AutoSize='true' FreezeColumn='0' >"
ListXML = ListXML & "<Column Name='Notes' Description='Notes' Link='false' />"
ListXML = ListXML & "</Columns>"
else
StkList = "<List>"
StkList = StkList & "<StockList>"
StkList = StkList & "<Notes>No Errors Found..." & CLineCounter & " record/s updated</Notes>"
StkList = StkList & "</StockList>"
StkList = StkList & "</List>"
ListXML = "<Columns PrimaryNode='StockList' Style='DataGrid' AutoSize='true' FreezeColumn='0' >"
ListXML = ListXML & "<Column Name='Notes' Description='Notes' Link='false' />"
ListXML = ListXML & "</Columns>"
End If
CustomizedPane.CodeObject.ListviewProperties = ListXML
CustomizedPane.CodeObject.ListviewData = StkList
End Function
Perhaps if they have a test company try it out in there first so you can see what it's doing?
NB: This was done for SYSPRO 6.1 and 7. Minor updates may be required to make this work in other versions.
You can also check out the SYSPRO Forums for help relating to syspro.
Hope this helps.

Related

Looping through unread emails, changing unread to read, using For Each

I wrote code to pick up unread email and with other criteria.
The code runs but For Each itm In olFolder.Items.Restrict(sFilter) is not working.
For example if there are 4 unread emails in the inbox the For Each should loop 4 times but the loop is happening only 2 times.
Sub ReadOutlookEmails_WithCriteria()
Dim olApp As Outlook.Application, olNs As Outlook.Namespace
Dim olFolder As Outlook.MAPIFolder, olMail As Outlook.MailItem
Dim eFolder As Outlook.Folder '~~> additional declaration
Dim Inbox As Outlook.MAPIFolder
Dim SubFolder As Outlook.MAPIFolder
Dim objAtt As Outlook.Attachment
Dim olItem As Outlook.MailItem
Dim olReply As MailItem ' Reply
Dim olRecip As Recipient
Dim i As Long
Dim x As Date, ws As Worksheet '~~> declare WS variable instead
Dim lrow As Long '~~> additional declaration
Set ws = ActiveSheet '~~> or you can be more explicit using the next line
Set EC = ThisWorkbook.Sheets("Email Search Criteria")
Set IE = ThisWorkbook.Sheets("Inbox Emails")
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Inbox = olNs.GetDefaultFolder(olFolderInbox)
Set SubFolder = Inbox.Folders("Rejected Emails")
Todays_Date = EC.Range("E2").Value
IE.Rows("2:10000").Clear
Incr = 2
For Each eFolder In olNs.GetDefaultFolder(olFolderInbox).Folders
If eFolder = "Mandatory Training Enrollment" Then 'IF_Check_1
Set olFolder = olNs.GetDefaultFolder(olFolderInbox).Folders(eFolder.Name): Debug.Print olFolder
sFilter = "[ReceivedTime] >= '" & Todays_Date & "' AND [UNREAD]=TRUE"
Debug.Print olFolder.Items.Restrict(sFilter).Count
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
For Each itm In olFolder.Items.Restrict(sFilter) ''''Problem is over here
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
If itm.Attachments.Count = EC.Range("B2") Then 'itm Like "*" & EC.Range("A2") & "*" And'IF_Check_2
For Each objAtt In itm.Attachments
Debug.Print "Subject Name - " & itm: Debug.Print "Attachment Type - " & objAtt.DisplayName
Debug.Print "Attachment Size - " & objAtt.Size: Debug.Print "Attachments Count - " & objAtt.Index
Debug.Print "Subject Name - " & EC.Range("A2"): Debug.Print "Attachment Type - " & EC.Range("C2")
Debug.Print "Attachment Size - " & EC.Range("D2"): Debug.Print "Attachments Count - " & EC.Range("B2")
If objAtt.Size <= EC.Range("D2") And UCase(objAtt.Filename) Like UCase("*" & EC.Range("C2")) Then
IE.Range("A" & Incr) = olFolder
IE.Range("B" & Incr) = itm.SenderName
IE.Range("C" & Incr) = itm
IE.Range("D" & Incr) = objAtt.DisplayName
IE.Range("E" & Incr) = itm.Attachments.Count
IE.Range("F" & Incr) = objAtt.Size
IE.Range("G" & Incr) = "Pass"
Set olReply = itm.ReplyAll
'Set olRecip = olReply.Recipients.Add("Email Address Here") ' Recipient Address
'olRecip.Type = olCC
olReply.Body = "Hello," & vbNewLine & vbNewLine & "Email Success" & vbNewLine & vbNewLine & "Thank you. " & vbCrLf & olReply.Body
olReply.Display
'olReply.SentOnBehalfOfName = onBehalfOf
'olReply.SendUsingAccount = getGenericMailboxAccount(onBehalfOf)
olReply.Send
itm.UnRead = False
End If
Next objAtt
ElseIf itm.Attachments.Count <> EC.Range("B2") Then 'IF_Check_2
FailReason1 = "Attament is not a PDF"
FailReason2 = "Attachment size is more than 10MB"
FailReason3 = "Attachment is missing with email"
FailReason4 = "Attachments are more than 1"
IE.Range("A" & Incr) = olFolder
IE.Range("B" & Incr) = itm.SenderName
IE.Range("C" & Incr) = itm
IE.Range("D" & Incr) = ""
IE.Range("E" & Incr) = itm.Attachments.Count
IE.Range("F" & Incr) = ""
IE.Range("G" & Incr) = "Fail"
EBody = "Hello," & vbNewLine & vbNewLine & "Email Not Success." & vbNewLine & vbNewLine _
& "Fail Reason Might Be One Of The Below Mentioned:" & vbNewLine & vbNewLine _
& "*" & FailReason1 & vbNewLine & vbNewLine _
& "*" & FailReason2 & vbNewLine & vbNewLine _
& "*" & FailReason3 & vbNewLine & vbNewLine _
& "*" & FailReason4 & vbNewLine & vbNewLine _
Set olReply = itm.ReplyAll
'Set olRecip = olReply.Recipients.Add("Email Address Here") ' Recipient Address
'olRecip.Type = olCC
'olReply.Body = "Hello," & vbCrLf & "Email Not Success" & vbCrLf & FailReason1 & vbCrLf & FailReason2 & vbCrLf & FailReason3 & vbCrLf & olReply.Body
olReply.Body = EBody & vbCrLf & olReply.Body
olReply.Display
'olReply.SentOnBehalfOfName = onBehalfOf
'olReply.SendUsingAccount = getGenericMailboxAccount(onBehalfOf)
olReply.Send
itm.UnRead = False
itm.Move SubFolder
End If 'IF_Check_2
Incr = Incr + 1
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Next itm ' Its passing to the next statement even though loop is not completed.
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Set olFolder = Nothing
End If ''IF_Check_1
Next eFolder
End Sub
Your are modifying (by setting the Unread property to false) the very collection you are iterating over.
Do not use foreach - use a down loop.
set restrItems = olFolder.Items.Restrict(sFilter)
For i = restrItems.Count to 1 Step -1
set itm = restrItems(i)
First of all, you need to make sure the date object is formatted in the way Outlook understands:
sFilter = "[ReceivedTime] >= '" & Todays_Date & "' AND [UNREAD]=TRUE"
Use the Format function available in VBA.
sFilter = "[ReceivedTime] > '" & Format(Todays_Date, "ddddd h:nn AMPM") & "'"

Is it possible to identify through OUTLOOK triggers/events to which shared mail box has received a new email?

We are trying to store new mail item components into excel and assign tkt id, have tried doing it with single shared mailbox and succeeded but we want to implement same for 20 shared mail boxes. how can outlook vba event/trigger identify as soon as new email arrives to one of the 20 shared mail boxes.
this is code which will only work for default inbox:
Private Sub inboxItems_ItemAdd(ByVal Item As Object)
Dim Msg As Outlook.MailItem
Dim MessageInfo
Dim Result
If TypeName(Item) = "MailItem" Then
Dim cn As Object
Dim sCon As String
Dim sSQL As String
Dim bytHasAttachment As String
Dim strAddress As String
Dim objSender, exUser
Dim olRecipient As Outlook.Recipient
Dim strToEmails, strCcEmails, strBCcEmails As String
For Each olRecipient In Item.Recipients
Dim mail As String
If olRecipient.AddressEntry Is Nothing Then
mail = olRecipient.Address
ElseIf olRecipient.AddressEntry.GetExchangeUser Is Nothing Then
mail = olRecipient.Address
Else
mail = olRecipient.AddressEntry.GetExchangeUser.PrimarySmtpAddress
End If
If olRecipient.Type = Outlook.OlMailRecipientType.olTo Then
strToEmails = strToEmails + mail & ";"
ElseIf olRecipient.Type = Outlook.OlMailRecipientType.olCC Then
strCcEmails = strCcEmails + mail & ";"
ElseIf olRecipient.Type = Outlook.OlMailRecipientType.olBCC Then
strBCcEmails = strBCcEmails + mail & ";"
End If
Next
With Item
If Item.Attachments.Count > 0 Then
bytHasAttachment = 1
Else
bytHasAttachment = 0
End If
End With
'On Error Resume Next 'PropertyAccessor can raise an exception if a property is not found
If Item.SenderEmailType = "SMTP" Then
strAddress = Item.SenderEmailAddress
Else
'read PidTagSenderSmtpAddress
strAddress = Item.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x5D01001F")
If Len(strAddress) = 0 Then
Set objSender = Item.Sender
If Not (objSender Is Nothing) Then
'read PR_SMTP_ADDRESS_W
strAddress = objSender.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x39FE001F")
If Len(strAddress) = 0 Then
Set exUser = objSender.GetExchangeUser
If Not (exUser Is Nothing) Then
strAddress = exUser.PrimarySmtpAddress
End If
End If
End If
End If
End If
On Error GoTo ErrorHandler
Set cn = CreateObject("ADODB.Connection")
sCon = "Driver=MySQL ODBC 8.0 ANSI Driver;SERVER=localhost;UID=root;PWD={Platinum#123};DATABASE=liva_dev_gm;PORT=3306;COLUMN_SIZE_S32=1;DFLT_BIGINT_BIND_STR=1"
cn.Open sCon
sSQL = "INSERT INTO tbl_gmna_emailmaster_inbox (eMail_Icon, eMail_MessageID, eMail_Folder, eMail_Act_Subject, eMail_From, eMail_TO, eMail_CC, " & _
"eMail_BCC, eMail_Body, eMail_DateReceived, eMail_TimeReceived, eMail_Anti_Post_Meridiem, eMail_Importance, eMail_HasAttachment) " & _
"VALUES (""" & Item.MessageClass & """, " & _
"""" & Item.EntryID & """, " & _
"""Inbox""" & ", " & _
"""" & Item.Subject & """, " & _
"""" & strAddress & """, " & _
"""" & strToEmails & """, " & _
"""" & strCcEmails & """, " & _
"""" & strBCcEmails & """, " & _
"""" & Item.Body & """, " & "'" & Format(Item.ReceivedTime, "YYYY-MM-DD") & "', " & "'" & Format(Item.ReceivedTime, "hh:mm:ss") & "', " & "'" & Format(Item.ReceivedTime, "am/pm") & "', " & "'" & Item.Importance & "', " & "'" & bytHasAttachment & "')"
cn.Execute sSQL
End If
ExitNewItem:
bytHasAttachment = ""
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ExitNewItem
End Sub
If the 20 shared mailboxes are in the navigation pane.
Option Explicit
Private WithEvents inboxItms As Items
Private WithEvents sharedInboxItms1 As Items
' ...
Private WithEvents sharedInboxItms20 As Items
Private Sub Application_Startup()
Dim defaultInbox As Folder
Dim sharedMailbox1 As Folder
Dim sharedInbox1 As Folder
' ...
Dim sharedMailbox20 As Folder
Dim sharedInbox20 As Folder
Set defaultInbox = Session.GetDefaultFolder(olFolderInbox)
Set inboxItms = defaultInbox.Items
Set sharedMailbox1 = Session.Folders("SharedMailbox1#somewhere.com")
Set sharedInbox1 = sharedMailbox1.Folders("Inbox")
' typo fixed
'Set sharedInboxItms1 = sharedInbox1.Folders("Inbox").Items
Set sharedInboxItms1 = sharedInbox1.Items
' ...
Set sharedMailbox20 = Session.Folders("SharedMailbox20#somewhere.com")
Set sharedInbox20 = sharedMailbox20.Folders("Inbox")
' typo fixed
'Set sharedInboxItms20 = sharedInbox20.Folders("Inbox").Items
Set sharedInboxItms20 = sharedInbox20.Items
End Sub
Private Sub inboxItms_ItemAdd(ByVal Item As Object)
' current code for default inbox
End Sub
Private Sub sharedInboxItms1_ItemAdd(ByVal Item As Object)
inboxItms_ItemAdd Item
End Sub
' ...
Private Sub sharedInboxItms20_ItemAdd(ByVal Item As Object)
inboxItms_ItemAdd Item
End Sub

VBA/Access: How to stop "You... FORM to be active window"

I want to be able to tell IF a form is the active window.
It seems simply invoking that method produces an error. I guess I could catch that error and run with it, but it's a backwards way of doing it.
Screen.ActiveForm.Name
This needs a form to be active. If I am breaking any rules of stackOverflow please be kind and remind me as I am new to forum.
Screen.parent, screen.activeControl, etc. What if VBA editor is open, as often it is?
Function CStatus(strStatus, ByRef intType As Integer, Optional ByRef erNo, Optional erMsg, Optional strDatum)
'pXname = "CStatus"
'pXStack = Left(pXStack, 500) & ">" & pXname
'Updates and manages the status bar
Dim strPreamble As String, strOut As String, strForm As String, strComment As String, strSQL As String, strPxStack As String, strCErrStack As String
Dim intColor As Double
Dim intPreLen As Integer
'On Error GoTo err_hand
'Color Codes
'12632256 = Lt Grey
'33023 = Orange
'65280 = Green
'16744576 = Steel Grey
'Define "Constants"
intPreLen = 350 'Length of previous message cache
'** Fix missings
If (IsMissing(strDatum) = True) Then strDatum = "[N/A]"
'** Other inits
strWindow = Screen.Parent.Name
strForm = Screen.ActiveForm.Name
'** intDebug ' Minimum Level of to report to status
'bEcho = True 'Whether to echo to status
intColor = errNoColor(intType)
'Error-level idiot explanations
strComment = "0"
If IsMissing(erNo) Then erNo = 0
If (IsNull(erMsg) = False) Then
If IsMissing(erMsg) = False Then strComment = erMsg
End If
strComment = errorTree(erNo)
strPreamble = Left(strPreamble, intPreLen) & "..."
strErrStack = Left(strErrStack, intPreLen) & " > " & pXname & ":" & intType
strCErrStack = strErrStack
reS:
If ((strForm = "finvmain") Or (strForm = "fclips")) Then Screen.ActiveForm.timeStatusUpdated = Now() 'Small field keeps time
If bEcho = True Then
strPxStack = ""
strCErrStack = "" 'Internal error stack
End If
strOut = Now() & " " & intType & " (" & strType & "): " & erNo & " " & strCErrStack & " >> " & strComment & " / " & strStatus & " [" & strDatum & "] .. " & strPreamble
If bEcho = True Then
If (strForm = "fInvMain") Then Screen.ActiveForm.txtStatus2 = Screen.ActiveForm.txtStatus 'Added second window to show previous message
Screen.ActiveForm.txtStatus = strOut
End If
Screen.ActiveForm.txtStatus.ForeColor = intColor
If strForm = "fInvMain" Then strTag = Screen.ActiveForm.Controls("txttag").value
'***Event Log
If erNo = "" Then erNo = 0
If IsMissing(erMsg) = True Then erMsg = ""
If IsMissing(strDatum) = True Then strDatum = ""
If Len(strPreamble) < 2 Then strPreamble = "[None]"
'Fixxed - Syntax Error for Some Odd Reason! Apr 27th
If ((strTag = Empty) And (strForm = "fInvMain")) Then strTag = Screen.ActiveForm.txtTag 'Attempt to add tag# to entry
strStatus = cleanString(strStatus)
strDatum = cleanString(strDatum)
strComment = cleanString(strComment)
strSQL = "INSERT INTO tEvents(txtdate, myerrno, interrno, myerrmsg, interrmsg, txtform, stack, process, Datum, idLink) VALUES ('" & Now() & "','" & intType & "','" & erNo & "','" & strStatus & "','" & strComment & "','" & strForm & "','" & strErrStack & "','" & pXname & "','" & strDatum & "','" & strTag & "');"
CurrentDb.Execute strSQL, dbFailOnError
Exit Function
err_hand:
If Err.Number = 2475 Then
bEcho = False
Resume reS
Else: MsgBox "555: CStatus Internal Error, Turn off error handling to view"
End If
End Function
I need a boolean true or false IF form is active. If it isn't, I can't put stuff into a textbox in that.
To determine if a particular form is open then set focus to form:
If CurrentProject.AllForms("finvmain").IsLoaded
strForm = "finvmain"
Elseif CurrentProject.AllForms("fclips").IsLoaded Then
strForm = "fclips"
End If
If strForm <> "" Then DoCmd.SelectObject acForm, strForm

How to export email addresses from outlook meeting request

I sent an outlook (2010) meeting request to all company (4000+) and now I would like to send an additional email to those who accepted the request or accepted tentatively.
How do I do that? When I hit Contact Atendees --> New Email to Atendees in the ribbon it just send a response to all company and not only those who accepted. I also tried to export the contacts but it can only export the name alias and not the entire email addresses.
Any suggestions?
Thanks
The basis of the solution is found here Get Meeting Attendee List Macro
Here it is with minor changes.
Option Explicit
Sub GetAttendeeList()
Dim objApp As Outlook.Application
Dim objItem As Object
Dim objAttendees As Outlook.Recipients
Dim objAttendeeReq As String
Dim objAttendeeOpt As String
Dim objOrganizer As String
Dim dtStart As Date
Dim dtEnd As Date
Dim strSubject As String
Dim strLocation As String
Dim strNotes As String
Dim strMeetStatus As String
Dim strCopyData As String
Dim strCount As String
Dim ino, it, ia, ide
Dim x As Long
Dim ListAttendees As mailitem
'On Error Resume Next
Set objApp = CreateObject("Outlook.Application")
Set objItem = GetCurrentItem()
Set objAttendees = objItem.Recipients
On Error GoTo EndClean:
' Is it an appointment
If objItem.Class <> 26 Then
MsgBox "This code only works with meetings."
GoTo EndClean:
End If
' Get the data
dtStart = objItem.Start
dtEnd = objItem.End
strSubject = objItem.Subject
strLocation = objItem.location
strNotes = objItem.body
objOrganizer = objItem.Organizer
objAttendeeReq = ""
objAttendeeOpt = ""
Set ListAttendees = Application.CreateItem(olMailItem) ' <---
' Get The Attendee List
For x = 1 To objAttendees.count
strMeetStatus = ""
Select Case objAttendees(x).MeetingResponseStatus
Case 0
strMeetStatus = "No Response (or Organizer)"
ino = ino + 1
Case 1
strMeetStatus = "Organizer"
ino = ino + 1
Case 2
strMeetStatus = "Tentative"
it = it + 1
ListAttendees.Recipients.Add objAttendees(x) ' <---
Case 3
strMeetStatus = "Accepted"
ia = ia + 1
ListAttendees.Recipients.Add objAttendees(x) ' <---
Case 4
strMeetStatus = "Declined"
ide = ide + 1
End Select
If objAttendees(x).Type = olRequired Then
objAttendeeReq = objAttendeeReq & objAttendees(x).Name & vbTab & strMeetStatus & vbCrLf
Else
objAttendeeOpt = objAttendeeOpt & objAttendees(x).Name & vbTab & strMeetStatus & vbCrLf
End If
Next
strCopyData = "Organizer: " & objOrganizer & vbCrLf & "Subject: " & strSubject & vbCrLf & _
"Location: " & strLocation & vbCrLf & "Start: " & dtStart & vbCrLf & "End: " & dtEnd & _
vbCrLf & vbCrLf & "Required: " & vbCrLf & objAttendeeReq & vbCrLf & "Optional: " & _
vbCrLf & objAttendeeOpt & vbCrLf & "NOTES " & vbCrLf & strNotes
strCount = "Accepted: " & ia & vbCrLf & _
"Declined: " & ide & vbCrLf & _
"Tentative: " & it & vbCrLf & _
"No response: " & ino
'Set ListAttendees = Application.CreateItem(olMailItem)
ListAttendees.body = strCopyData & vbCrLf & strCount
ListAttendees.Display
ListAttendees.Recipients.ResolveAll ' <---
EndClean:
Set objApp = Nothing
Set objItem = Nothing
Set objAttendees = Nothing
End Sub
Building upon what #niton wrote, I've added support for checking against the Global Address List. This code could be extended to search all address lists available to you by iterating through myAddressLists, however, in most cases, that will probably be more than wanted.
Note that this isn't optimized for speed, but even a list with a few hundred people invited against a GAL of tens of thousands won't take a computer very long to iterate through. Since this doesn't get run very often, the time saved for optimizing this just didn't seem worth it.
Option Explicit
Sub GetAttendeeList()
Dim x As Integer
Dim y As Integer
Dim ino As Integer
Dim it As Integer
Dim ia As Integer
Dim ide As Integer
Dim objApp As Outlook.Application
Dim objItem As Object
Dim objAttendees As Outlook.Recipients
Dim objAttendeeReq As String
Dim objAttendeeOpt As String
Dim strAttendeeName As String
Dim strAttendeeEmail As String
Dim objOrganizer As String
Dim dtStart As Date
Dim dtEnd As Date
Dim strSubject As String
Dim strLocation As String
Dim strNotes As String
Dim strMeetStatus As String
Dim strCopyData As String
Dim strCount As String
Dim strCity As String
Dim folContacts As Outlook.MAPIFolder
Dim oContact As Outlook.ContactItem
Dim colItems As Outlook.Items
Dim oNS As Outlook.NameSpace
Dim ListAttendees As MailItem
Dim strNewRecord As String
Dim myAddressLists As AddressLists
Dim myAddressEntries As AddressEntries
Dim myAddressEntry As AddressEntry
Dim myExchangeUser As ExchangeUser
Dim myExchangeDL As ExchangeDistributionList
Dim myContactItem As ContactItem
On Error Resume Next
Set objApp = CreateObject("Outlook.Application")
Set oNS = Application.GetNamespace("MAPI")
Set folContacts = oNS.GetDefaultFolder(olFolderContacts)
Set colItems = folContacts.Items
Set myAddressLists = oNS.AddressLists
Set myAddressEntries = myAddressLists.Item("Global Address List").AddressEntries
Set objItem = GetCurrentItem()
Set objAttendees = objItem.Recipients
On Error GoTo EndClean:
' Is it an appointment
If objItem.Class <> 26 Then
MsgBox "This code only works with meetings."
GoTo EndClean:
End If
' Get the data
dtStart = objItem.Start
dtEnd = objItem.End
strSubject = objItem.Subject
strLocation = objItem.Location
strNotes = objItem.Body
objOrganizer = objItem.Organizer
objAttendeeReq = ""
objAttendeeOpt = ""
' Get The Attendee List
For x = 1 To objAttendees.Count
strMeetStatus = ""
Select Case objAttendees(x).MeetingResponseStatus
Case 0
strMeetStatus = "No Response (or Organizer)"
ino = ino + 1
Case 1
strMeetStatus = "Organizer"
ino = ino + 1
Case 2
strMeetStatus = "Tentative"
it = it + 1
Case 3
strMeetStatus = "Accepted"
ia = ia + 1
Case 4
strMeetStatus = "Declined"
ide = ide + 1
End Select
strAttendeeName = objAttendees(x).Name
strAttendeeEmail = objAttendees(x).Address
Set oContact = colItems.Find("[Email1Address] = '" & strAttendeeEmail & "'")
If Not oContact Is Nothing Then
Debug.Print "Test", oContact.BusinessAddressCity
strCity = oContact.MailingAddressCity & ", " & oContact.MailingAddressState
End If
If InStr(strAttendeeEmail, "#") = 0 Then
Debug.Print "Searching: " & objAttendees(x).Name
Set myAddressEntry = myAddressEntries.GetFirst()
Do While Not myAddressEntry Is Nothing
If myAddressEntry.Address Like objAttendees(x).Address Then
Debug.Print "Found: " & myAddressEntry.Name
Set myExchangeUser = myAddressEntry.GetExchangeUser()
Set myExchangeDL = myAddressEntry.GetExchangeDistributionList()
Set myContactItem = myAddressEntry.GetContact()
If Not myExchangeUser Is Nothing Then
strAttendeeEmail = myExchangeUser.PrimarySmtpAddress
End If
If Not myExchangeDL Is Nothing Then
strAttendeeEmail = myExchangeDL.PrimarySmtpAddress
End If
If Not myContactItem Is Nothing Then
strAttendeeEmail = myContactItem.Email1Address
End If
GoTo ContactFound
End If
Set myAddressEntry = myAddressEntries.GetNext()
Loop
End If
ContactFound:
strNewRecord = objAttendees(x).Name & vbTab & strAttendeeEmail & vbTab & strMeetStatus & vbTab & strCity & vbCrLf
If objAttendees(x).Type = olRequired Then
objAttendeeReq = objAttendeeReq & strNewRecord
Else
objAttendeeOpt = objAttendeeOpt & strNewRecord
End If
Next
strCopyData = "Organizer: " & objOrganizer & vbCrLf & "Subject: " & strSubject & vbCrLf & _
"Location: " & strLocation & vbCrLf & "Start: " & dtStart & vbCrLf & "End: " & dtEnd & _
vbCrLf & vbCrLf & "Required: " & vbCrLf & objAttendeeReq & vbCrLf & "Optional: " & _
vbCrLf & objAttendeeOpt & vbCrLf & "NOTES " & vbCrLf & strNotes
strCount = "Accepted: " & ia & vbCrLf & _
"Declined: " & ide & vbCrLf & _
"Tentative: " & it & vbCrLf & _
"No response: " & ino
Set ListAttendees = Application.CreateItem(olMailItem)
ListAttendees.Body = strCopyData & vbCrLf & strCount & vbCrLf & Time
ListAttendees.Display
EndClean:
Set objApp = Nothing
Set objItem = Nothing
Set objAttendees = Nothing
End Sub
Function GetCurrentItem() As Object
Dim objApp As Outlook.Application
Set objApp = Application
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
End Select
Set objApp = Nothing
End Function

WMI to get drive letter association with physical drive path, misses CDROMs

I'm running the following WMI script to get the associations between drive letters and physical drives on the system, but for some reason it omits CDROMs/DVD-ROMs. Can someone tell me how to get those as well?
ComputerName = "."
Set wmiServices = GetObject _
("winmgmts:{impersonationLevel=Impersonate}!//" & ComputerName)
Set wmiDiskDrives = wmiServices.ExecQuery _
("SELECT DeviceID FROM Win32_DiskDrive")
For Each wmiDiskDrive In wmiDiskDrives
strEscapedDeviceID = _
Replace(wmiDiskDrive.DeviceID, "\", "\\", 1, -1, vbTextCompare)
Set wmiDiskPartitions = wmiServices.ExecQuery _
("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & _
strEscapedDeviceID & """} WHERE " & _
"AssocClass = Win32_DiskDriveToDiskPartition")
For Each wmiDiskPartition In wmiDiskPartitions
Set wmiLogicalDisks = wmiServices.ExecQuery _
("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & _
wmiDiskPartition.DeviceID & """} WHERE " & _
"AssocClass = Win32_LogicalDiskToPartition")
For Each wmiLogicalDisk In wmiLogicalDisks
WScript.Echo wmiLogicalDisk.DeviceID & " = " & wmiDiskDrive.DeviceID
Next
Next
Next
Considering all of the comments thus far, here is a script that adds the capability to list CD-Rom drives.
ComputerName = "."
Set dictDrives = CreateObject("Scripting.Dictionary")
Set listDriveLetters = CreateObject("System.Collections.ArrayList")
Set wmiServices = GetObject _
("winmgmts:{impersonationLevel=Impersonate}!//" & ComputerName)
Set wmiDiskDrives = wmiServices.ExecQuery _
("SELECT DeviceID FROM Win32_DiskDrive")
For Each wmiDiskDrive In wmiDiskDrives
strEscapedDeviceID = Replace(wmiDiskDrive.DeviceID, "\", "\\", 1, -1, vbTextCompare)
Set wmiDiskPartitions = wmiServices.ExecQuery _
("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & _
strEscapedDeviceID & """} WHERE " & _
"AssocClass = Win32_DiskDriveToDiskPartition")
For Each wmiDiskPartition In wmiDiskPartitions
Set wmiLogicalDisks = wmiServices.ExecQuery _
("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & _
wmiDiskPartition.DeviceID & """} WHERE " & _
"AssocClass = Win32_LogicalDiskToPartition")
For Each wmiLogicalDisk In wmiLogicalDisks
listDriveLetters.Add wmiLogicalDisk.DeviceID
dictDrives.Add wmiLogicalDisk.DeviceID, wmiDiskDrive.DeviceID
Next
Next
Next
Set wmiCDROMDrives = wmiServices.ExecQuery _
("Select DeviceID, Drive, MediaLoaded from Win32_CDROMDrive")
For Each wmiCDROMDrive in wmiCDROMDrives
If wmiCDROMDrive.MediaLoaded Then ' Only show drives with inserted media
listDriveLetters.Add wmiCDROMDrive.Drive
dictDrives.Add wmiCDROMDrive.Drive, wmiCDROMDrive.DeviceID
End If
Next
listDriveLetters.Sort ' List the drives in alphabetical order
For Each strDriveLetter in listDriveLetters
WScript.Echo strDriveLetter & " = " & dictDrives.Item(strDriveLetter)
Next
I think you wouldn need to use the Win32_CDROMDrive WMI class to access CD-ROM info. The code you have above is looking for physical drives in the Win32_DiskDrive class, it excludes CD_ROM
You could additional lines to get similar data - but not the same given CD-ROMs don't have the Partition characteristics that your current code does
ComputerName = "."
Set wmiServices = GetObject _
("winmgmts:{impersonationLevel=Impersonate}!//" & ComputerName)
Set wmiDiskDrives = wmiServices.ExecQuery _
("SELECT * FROM Win32_CDROMDrive")
For Each wmiDiskDrive In wmiDiskDrives
MsgBox wmiDiskDrive.drive & "=" & wmiDiskDrive.DeviceID
Next
Instead I think this different VBS may do what you want - the may part as I dont think the partition info is relevant to you.
vbs version
Dim objFSO
Dim colDrives
Dim strOut
Dim strArray
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colDrives = objFSO.Drives
strArray = Array("Unknown", "Removable", "Fixed", "Network", "CD-ROM", "RAM Disk")
On Error Resume Next
'File system errors for virtual drives
For Each objDrive In colDrives
strOut = "Drive letter: " & objDrive.DriveLetter & vbNewLine
strOut = strOut & ("Drive type: " & strArray(objDrive.DriveType) & vbNewLine)
strOut = strOut & ("File system: " & objDrive.FileSystem & vbNewLine)
strOut = strOut & ("Path: " & objDrive.Path)
wscript.echo strOut
Next
On Error GoTo 0
vba version
Sub Test()
Dim objFSO As Object
Dim colDrives As Object
Dim strOut As String
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colDrives = objFSO.Drives
On Error Resume Next
'File system errors for virtual drives
For Each objDrive In colDrives
strOut = "Drive letter: " & objDrive.DriveLetter & vbNewLine
strOut = strOut & ("Drive type: " & Choose(objDrive.DriveType + 1, "Unknown", "Removable", "Fixed", "Network", "CD-ROM", "RAM Disk") & vbNewLine)
strOut = strOut & ("File system: " & objDrive.FileSystem & vbNewLine)
strOut = strOut & ("Path: " & objDrive.Path)
MsgBox strOut
Next
On Error GoTo 0
End Sub