How to update BegAtt & EndAtt values by MDB query? - ms-access

I want to update the BegAtt & EndAtt values based on the Control Start, Control Stop, Application, and Record Type fields in MDB by query.
Below is the record set of my MDB database where I want to update BegAtt and EndAtt values based on the parent record which has Record Type = Email:
Application Record Type Control Start Control Stop BegAtt EndAtt
Outlook Mail Document Email 3rd-Party_00000040 3rd-Party_00000040
Adobe Acrobat Document Email-Attachment 3rd-Party_00000041 3rd-Party_00000044
Adobe Acrobat Document Email-Attachment 3rd-Party_00000045 3rd-Party_00000045
Adobe Acrobat Document Email-Attachment 3rd-Party_00000046 3rd-Party_00000049
Adobe Acrobat Document Email-Attachment 3rd-Party_00000050 3rd-Party_00000181
Adobe Acrobat Document Email-Attachment 3rd-Party_00000182 3rd-Party_00000223
Adobe Acrobat Document Email-Attachment 3rd-Party_00000224 3rd-Party_00000243
Adobe Acrobat Document Email-Attachment 3rd-Party_00000244 3rd-Party_00000250
Adobe Acrobat Document Email-Attachment 3rd-Party_00000251 3rd-Party_00000460
Outlook Mail Document Email 3rd-Party_00000461 3rd-Party_00000461
Adobe Acrobat Document Email-Attachment 3rd-Party_00000462 3rd-Party_00000611
The BegAtt value should be first value of main record (Record Type = Email) and EndAtt value should be last value of family (record Type = Email-Attachment). Below is the desired result:
Application Record Type Control Start Control Stop BegAtt EndAtt
Outlook Mail Document Email 3rd-Party_00000040 3rd-Party_00000040 3rd-Party_00000040 3rd-Party_00000460
Adobe Acrobat Document Email-Attachment 3rd-Party_00000041 3rd-Party_00000044 3rd-Party_00000040 3rd-Party_00000460
Adobe Acrobat Document Email-Attachment 3rd-Party_00000045 3rd-Party_00000045 3rd-Party_00000040 3rd-Party_00000460
Adobe Acrobat Document Email-Attachment 3rd-Party_00000046 3rd-Party_00000049 3rd-Party_00000040 3rd-Party_00000460
Adobe Acrobat Document Email-Attachment 3rd-Party_00000050 3rd-Party_00000181 3rd-Party_00000040 3rd-Party_00000460
Adobe Acrobat Document Email-Attachment 3rd-Party_00000182 3rd-Party_00000223 3rd-Party_00000040 3rd-Party_00000460
Adobe Acrobat Document Email-Attachment 3rd-Party_00000224 3rd-Party_00000243 3rd-Party_00000040 3rd-Party_00000460
Adobe Acrobat Document Email-Attachment 3rd-Party_00000244 3rd-Party_00000250 3rd-Party_00000040 3rd-Party_00000460
Adobe Acrobat Document Email-Attachment 3rd-Party_00000251 3rd-Party_00000460 3rd-Party_00000040 3rd-Party_00000460
Outlook Mail Document Email 3rd-Party_00000461 3rd-Party_00000461 3rd-Party_00000461 3rd-Party_00000611
Adobe Acrobat Document Email-Attachment 3rd-Party_00000462 3rd-Party_00000611 3rd-Party_00000461 3rd-Party_00000611
I tried below code which gets incorrect result.
SELECT [3rd-Party001_Main].[Record Type], Min([3rd-Party001_Main].[Control Start]) AS [MinOfControl Start], Max([3rd-Party001_Main].[Control Stop]) AS [MaxOfControl Stop]
FROM [3rd-Party001_Main]
GROUP BY [3rd-Party001_Main].[Record Type];

Since there is no 'family' identifier, a query object alone will not accomplish what you want. Need VBA code looping through recordset checking when values change to determine start of 'family' group, set value of StartAtt field, and run an UPDATE action SQL to set EndAtt field. Based on data sample, consider:
Sub SetRange()
Dim rs As DAO.Recordset, strStart As String, strEnd As String, strApp As String
Set rs = CurrentDb.OpenRecordset("SELECT * FROM [3rd-Party001_Main] WHERE BegAtt Is Null ORDER BY ControlStart;")
Do
If rs!Application Like "Outlook*" Then
strStart = rs!ControlStart
End If
strEnd = rs!ControlStop
rs.Edit
rs!StartAtt = strStart
rs.Update
rs.MoveNext
If Not rs.EOF Then strApp = rs!Application
If (Not rs.EOF And strApp Like "Outlook*") Or rs.EOF Then
CurrentDb.Execute "UPDATE [3rd-Party001_Main] SET EndAtt = '" & strEnd & "' WHERE StartAtt='" & strStart & "'"
End If
Loop Until rs.EOF
End Sub
Advise not to use spaces nor punctuation/special characters in naming convention.

Related

How to open the correct version of Excel when 2 versions are installed

I have an access VBA script that exports to Excel. It opens the workbook, copies & formats the data and saves the workbook. It's worked for years. It worked on my old system with Office 13, and it works on my new system with Office 16. Now I'm trying to run this on another PC that was just set up - it has Office 13 installed, but may also have the Office 16 version installed that came with the new PC.
When I manually open Excel, Excel 2013 opens as it should. When my Access code runs and tries to open Excel, it seems to be going to the new version - and the code stops working, I think because the Office 16 account isn't set up and when Excel opens it goes to the Office 16 activation screen instead of opening the workbook.
The export macro code is
Public Function Export_data(Optional table As String, Optional opt As String = "")
Set wb_app = CreateObject("Excel.Application")
wb_app.Visible = False
wb_app.displayalerts = False
path = DLookUp("[report folder]", "folder")
If opt <> "" Then
FileName = path & "\" & opt & ".xlsm"
Set wb_obj = wb_app.workbooks.Open(FileName)
End If
The error occurs at "wb_app.workbooks.open" with the error "Unable to get the Open property of the Workbooks class." When I set .Visible to True and look at what Excel is doing, it's going to the activation screen for the Office 16 account.
How can I change the VBA code to direct it to the correct version of Excel?
You can specify the version by using the 2-digit office version at the end of the file, e.g.:
Set wb_app = CreateObject("Excel.Application.14") 'Office 2010
You can look in the registry under HKEY_CLASSES_ROOT to see what's available. Of course, you can query the registry using VBA if you want.

Can't create shortcut to .ACCDE file

I have created an Access 2013 db that I need to deploy to several machines, some of which don't have Access installed on them. I can create a .ACCDE file from the .ACCDB file. But when I create a shortcut to the .ACCDE file using VBScript, the shortcut insists on setting the "Opens With" field to "MS Access". Since the .ACCDE file is an executable file, I need it to open directly, not to open up using Access. How can I get the VBScript to set this? Here's what I am using so far.
set objFileSys= CreateObject("Scripting.FileSystemObject")
Set oWS = WScript.CreateObject("WScript.Shell")
If objFileSys.FileExists(oWS.SpecialFolders("Desktop") + "\ClientData.lnk") Then
WScript.Quit
End If
Set oLink = oWS.CreateShortcut(oWS.SpecialFolders("Desktop") + "\ClientData.lnk")
oLink.TargetPath = "C:\Client Data\UnityClients.accde"
oLink.Description = "Client Data"
oLink.WorkingDirectory = "C:\Client Data"
oLink.WindowStyle = 3
oLink.IconLocation = "C:\Client Data\ufsLogo.ico"
REM oLink.OpensWith = ""
oLink.Save
I tried setting the "OpenWith" property, but that's not valid. :-(
I think accde files run on machines without full blown Access still need the Access Run Time...https://www.microsoft.com/en-us/download/details.aspx?id=39358

One Ribbon XML for Outlook 2007 and Outlook 2010

I am trying to use Ribbon XML to create custom ribbon on Outlook 2010 and 2007, I have one XML file for the ribbon, and it works fine for Outlook 2010, the ribbon appear and is working. But it is not working on Outlook 2007. Since Outlook 2007 does not have ribbon, so in the GetCustomUI() function I have checking on the Outlook version using Application.Version, if the version is >= 14 then it will load the XML file, and if it is < 14 then I called a subroutine to create the menubar using commandbarcontrol, but this didn't work. The add in is not loaded during the startup of Outlook 2007.
Protected Overrides Function CreateRibbonExtensibilityObject() As Microsoft.Office.Core.IRibbonExtensibility
Return New MyRibbon
End Function
Public Function GetCustomUI(ByVal ribbonID As String) As String Implements Microsoft.Office.Core.IRibbonExtensibility.GetCustomUI
If iOfficeVersion >= 14 Then
Return GetResourceText("MyRibbon.xml")
ElseIf iOfficeVersion < 14 Then
'Load commandbar UI
End If
End Function
How do I use the Ribbon XML feature to support both Outlook 2010 and 2007?
I found out the problem. The problem is the Office.dll (C:\Program Files (x86)\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14\Office.dll) has the property "Embed Interop Types" set to False. This file is not available in user PC.

Splitting a Multi-Page MS Access report into individual pdf files based on a Customer ID?

I'm looking to split a multi-page access report up into individual pdf files based on a Customer ID and then saving those pdf files based on the Customer Name (or ID).
I've looked into 'printing'/'converting' the report into one massive pdf file and splitting it there, but some customer invoices span two+ pages, therefore splitting that one pdf file page-by-page doesn't work.
Any help would be greatly appreciated; if anyone needs more clarification on anything, don't hesitate to let me know.
This can be easy with Access 2007 (see note below) or later.
Open your report using the WhereCondition parameter to limit the record source to a specific customer.
DoCmd.OpenReport "rptFoo", acViewPreview, , "Customer_ID = 1"
Then use OutputTo to save it as PDF with a file name you supply.
DoCmd.OutputTo acOutputReport, "", acFormatPDF, "Spacely_Sprockets.pdf"
Close the report afterward.
DoCmd.Close acReport, "rptFoo"
You could create a procedure which opens a recordset for Customer_ID and Customer_Name data, then use those 3 commands with values from each row.
If your Access version is older than 2007, you'll have to tell us about the method you're using to create PDF files.
Note: For Access 2007, Office Service Pack 2 provides Built-in Save As PDF/XPS support.
PDF printing is available with MS Access 2010, for 2007, you can install an add-on from Microsoft : Print, share, and protect files in the PDF and XPS file formats
For versions prior to 2007, you can use :
Stephen LeBan's ReportToPDF consists of just two DLLs but only works with MS Access
CutePDF is free and easy to use.
PDFCreator is also free and can be fully automated with VBA (though I have not used it lately, I believe this feature is still available)
Any number of paid-for PDF creators.
The WHERE argument for OpenReport has been available since the 2003 version (also OpenReport 2010)
To print a report for all customers for version 2003, 2007 and 2010, you can loop through the relevant file and
Dim rs AS DAO.Recordset
Set rs = CurrentDB.OpenRecordset("SELECT DISTINCT CustimerID FROM Invoices")
Do While Not rs.EOF
''expression.OpenReport(ReportName, View, FilterName,
'' WhereCondition, WindowMode) -- 2010 has OpenArgs
DoCmd.OpenReport "Invoices",<..>,,"CustomerID=" & rs!CustomerID
''OutputTo or other relevant code
rs.MoveNext
Loop
Getting a PDF then depends on your version and the tools you have installed. If you are using PDFCreator or CutePDF, for example, you can use acViewNormal for the view. PDFCreator set up will allow you to assign a file name in advance, for CutePDF, you will have to fill in a file name. For Access 2007 and 2010, you can use OutputTo, as has already been mentioned, so acViewPreview is best.
To email a report for 2007 and 2010, you can use SendObject. For earlier versions, you will need quite a bit more code. The easiest option is probably to automate Outlook.

How do you extract data from vendor website in vbscript?

I have programmed a post image HTA which is launched after an XP image has been loaded onto a computer. The HTA gathers information from the user (ie primary user name, department, etc) and updates the registry under a custom key. Management has asked if I can pull the computer's warranty information (specifically the warranty end date) from the vendor's website (in this case Lenovo) and update the registry with this info. Lenovo allows anonymous lookup using computer type and serial number and returns a page showing warranty information. Is there a way using vbscript (or maybe javascript?) to parse the returned page for the data I'm looking for?
Thanks in advance,
Gill
Using an HTML parser would probably be a more robust way to do this, but it's easy with VBScript to just script Internet Explorer through OLE Automation.
Dim ie, frm
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate "http://www-307.ibm.com/pc/support/site.wss/" & _
"document.do?lndocid=LOOK-WARNTY#sw"
Do Until ie.ReadyState = 4 '' READYSTATE_COMPLETE
WScript.Sleep 100
Loop
Set frm = ie.Document.Forms.warrantyLookup
frm.type.Value = "2644"
frm.serial.Value = "23AB123"
frm.Submit
Do Until ie.Document.ReadyState = "complete"
WScript.Sleep 100
Loop
'' Locate the information you want to scrape from the
'' ie.Document DOM at this point
ie.Quit
You can scrape the page that is returned fairly easily, all it really takes is an HTML parser, and then knowledge of where the information you want is located within the returned page. I do not know of any VBScript HTML parsers, but I am sure they exist. If you cannot find one, however, you can call out to an external program from locally running code, so you could write a page scraping utility in any number of languages (or use some sort of grep utility), and that may do what you are looking for.