Custom Hyperlink Title in MS Access Datasheet - ms-access

I'm writing to see if anyone can tell me the fastest way of extracting filenames from a network drive I have offsite. I have some search criteria provided by users with the help of a userform in Access.
I've tried using FSO which in my experience in this situation is the slowest.
I've also tried using CMD with WScript.Shell, which is faster, but I've recorded that it take approximately 7 minutes to perform the check with the macro. Using the Windows search bar in an explorer window provides results in about a minute or less. The parent folders I am searching through have approximately 35,000 folders each containing about 1 to 2 files.
Here is the command I use with CMD with WScript.Shell :
strTemp = CreateObject("WScript.Shell").Exec("CMD /C DIR """ & "N:\" & _
Me.txtRegion.Value & "\" & Me.txtYear.Value & "\" & _
Me.txtDossier.Value & "*.*"" /S /B /A:-D").StdOut.ReadAll
The results are then split into an array and processed.
Does anyone have any suggestions for how to improve this code?

Related

Access VBA not recognizing range in Excel spreadsheet

I am having a most frustrating time time with the DoCmd.TransferSpreadsheet method. I have a workbook with multiple worksheets in which users are updating data and I have a script that puts all the records back into a single sheet, links the spreadsheet, and updates the data in my Access DB. My problem is in the Range parameter. I pass the following string and get the following error:
DoCmd.TransferSpreadsheet TransferType:=acLink, SpreadsheetType:=acSpreadsheetTypeExcel12Xml, _
TableName:=linkSheet, fileName:=Wb.Path & "\" & Wb.name, _
HasFieldNames:=True, Range:="AccessUpdate!updateTable"
The Microsoft Access database engine could not find the object 'AccessUpdate$updateTable'. Make sure the object exists and that you spell its name and the path name correctly. If 'Access_Update$updateTable' is not a local object, check your network connection or contact the server administrator.
I can't seem to understand why it substitutes the dollar sign for the bang. Any other help in understanding how to specify the range would also be appreciated.
Thanks!
I know this is an year old question but it is an almost timeless problem.
I'm trying to do the same from the Excel side and bumping into the same problem. Access switching the sheet separator "!" for "$"
I found that this is a bug from Access 2000 that was never corrected. Or better, it was partially corrected at some point. So depending on your Access build and the size of the range [yes, size, since this is a bug from Access 2000] the solutions provided by Cisco or HansUp will work.
Another sources explaining the problem and a similar solution is provided by the MS$ themselves
https://answers.microsoft.com/en-us/office/forum/office_2007-access/transferspreadsheet-error-3011-can-not-file-sheet/980b2dc1-9ee1-4b3e-9c3c-a810f1428496
with the help of Bob Larson Former Access MVP (2008-2010) [see his very last post]
Now, if your range is on a different sheet with more than 65536 rows, this bug will come back.
See here for reference
Funny enough, if this is Sheet1 [yes, index 1 of all sheets] it will work with any range size. But any other sheet it wil fail.
This was my original range: BASE!A2:X68506, named REF_ACCESS. BASE is my Sheet5. Access 2010 & Excel 2010
I tried ActivateSheet, assign to string inside command, assign to string outside command, replace(,"$","!""), nothing worked. Even on Office 2016 from a friend
If I use "BASE!A2:X64506", it works. If I use "A2:X68506", Access assumes Sheet1 and works. Attention that all ranges do not have "$", but I guess you already know that
My last test was something like this monster
DoCmd.TransferSpreadsheet TransferType:=acImport, SpreadsheetType:=9, TableName:="TEST", Filename:=ThisWorkbook.FullName, HasFieldNames:=False, Range:=Worksheets("BASE").Name & "!" & Replace(Left(Worksheets("BASE").Range("REF_ACCESS").Address, Len(Worksheets("BASE").Range("REF_ACCESS").Address) - 1), "$", "")
A test that using my range within the 65536 row limit [6553 to be precise] would work. And it did.
So I see solutions with only two options for now. Either copy your range to Sheet1 or another sheet, as RyanM did, or divide your range in multiple DoCmd with 65536 rows.
I know it is long. Sorry, this was 2 full days looking for an answer without any real solution. I hope this helps other people with the same problem.
I tried multiple methods for getting around this without making major modifications to my code but with no avail. I did come up with a solution but it is rather resource intensive and messy. However, in case someone has a similar issue, I will post it here. I wound up separating my update sheet into it's own file from the rest of the workbook and linking that file. This prevented Access from trying to link a different sheet and got me around the whole Range issue. I know it's not elegant or efficient but it worked. If I figure out a cleaner way I'll post it here.
Set xl = Wb.Parent
xl.ScreenUpdating = False
xl.DisplayAlerts = False
strFile = mypath & "\TempIss.xlsx"
For i = 1 To Wb.Worksheets.count
If InStr(1, Wb.Worksheets(i).name, "Update", vbTextCompare) > 0 Then
tableId = i
Exit For
End If
Next i
If tableId = 0 Then
MsgBox "This workbook does not seem to have the necessary worksheet for updating " & _
"the Participant Issues Log in Access.", vbInformation, "Uh oh..."
Exit Function
Else
Set upWs = Wb.Worksheets(i)
upWs.Select
upWs.Copy
xl.ActiveSheet.SaveAs fileName:=strFile
xl.ActiveWorkbook.Close
Call rmSheet(Wb, "AccessUpdate")
xl.ScreenUpdating = True
linkSheet = "tempIssLog"
DoCmd.TransferSpreadsheet TransferType:=acImport, SpreadsheetType:=acSpreadsheetTypeExcel12Xml, _
TableName:=linkSheet, fileName:=strFile, _
HasFieldNames:=True
Kill (strFile)
If the range is a named range (in Excel) follow the instruction above (HansUp comment).
If the range is defined in MS-Access be sure to pass a string (something like "A1:G12") and not the control name.
Dim StrRange as variant
Dim NameofMySheet as string
NameofMySheet = "xxxxxx" ' <- Put here the name of your Excel Sheet
StrRange = NameofMySheet & "!" & "A1:G12"
DoCmd.TransferSpreadsheet TransferType:=acLink, SpreadsheetType:=acSpreadsheetTypeExcel12Xml, _
TableName:=linkSheet, fileName:=Wb.Path & "\" & Wb.name, _
HasFieldNames:=True, Range:= StrRange
Note 1: StrRange with no quotes!

Restructuring code in two .bat files

I have developed a program (1) coded in batch named info.bat:
Store information about a computer,
Manipulates information and outputs details to %ComputerName%.csv file.
Then a .vbs file (2) is called, and this outputs a list of installed programs to %ComputerName%-programs.txt file in the same directory as the .csv file.
The batch file ends when the .vbs has finished, and user is shown a Cmd window ready for next command.
Next another program StripSoftware.bat (3) is manually started:
It creates %ComputerName%-programs-to-check.txt,
Adds OS version and %ComputerName%,
Examines entries in %ComputerName%-programs.txt,
Takes out unwanted matches (using findstr and switches),
Removes empty lines,
Sorts results ascending,
Then puts them into %ComputerName%-programs-to-check.txt
Aim:
I need to use the software entries (1 line per software name) in %ComputerName%-programs-to-check.txt, concatenate them together, then put them into the software_needed column in the .csv file.
Output:
The output needed is a .csv file or preferably an .xlsx file with the following headers in the 1st row, and applicable information in the 2nd row.
.csv example:
v34,ID,Asset,Sys_Type,Model,NHC Asset,New Sys Type,New Model,New Sys Asset,Domain,DIR,Site,Team,Location,Post,Name,Postcode,Local Printers,Network Printers,Eth_MACs,Wifi_MACs,Phone_MAC,Software Needed,OTHER_ASSET,OS_VER,Hostname,Software_Notes,Other_Notes,IGEL_REC
,,ABCDEFG,PC,A123,,,,,XXXX,Unknown,,,,,,, , ,||"XX-XX-XX-XX-XX-XX"|"Disabled",,,Not Used,ABCDEFG,Win XP Pro,ABCDEFG,,,
Partial contents of info.bat:
#echo OFF
setlocal enableextensions enabledelayedexpansion
SET file="%~dp0%computername%.csv"
If Exist %file% Del %file%
echo %Version_tool%,ID,Asset,Sys_Type,Model,NHC Asset,New Sys Type,New Model,New Sys Asset,Domain,DIR,Site,Team,Location,Post,Name,Postcode,Local Printers,Network Printers,Eth_MACs,Wifi_MACs,Phone_MAC,Software Needed,OTHER_ASSET,OS_VER,Hostname,Software_Notes,Other_Notes,IGEL_REC>>%file%
rem ========= Other code =========
echo ,%ID%,%serialnumber%,PC,%model%,,,,,%userdomain%,Unknown,,,,,,,%Local_Printers%,!network_printers!,!Eth_MACs!,!Wifi_MACs!,!Phone_MACs!,Not Used,%system%,%osname%,%Hostname%,,,%IGEL REC%>> %file%
SET file2="%~dp0%computername%-programs.txt"
If Exist %file2% Del %file2%
start /b cmd /k "cscript //nologo programs_02.vbs >> %file2%"
echo Batch Tool should finish in a few seconds ...
Contents of .vbs file:
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
strComputer = "."
strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
strEntry1a = "DisplayName"
strEntry1b = "QuietDisplayName"
strEntry2 = "InstallDate"
strEntry3 = "VersionMajor"
strEntry4 = "VersionMinor"
strEntry5 = "EstimatedSize"
Set objReg = GetObject("winmgmts://" & strComputer & "/root/default:StdRegProv")
objReg.EnumKey HKLM, strKey, arrSubkeys
WScript.Echo "Installed Applications" & VbCrLf
For Each strSubkey In arrSubkeys
intRet1 = objReg.GetStringValue(HKLM, strKey & strSubkey, strEntry1a, strValue1)
If intRet1 <> 0 Then
objReg.GetStringValue HKLM, strKey & strSubkey, strEntry1b, strValue1
End If
If strValue1 <> "" Then
WScript.Echo VbCrLf & strValue1
End If
objReg.GetStringValue HKLM, strKey & strSubkey, strEntry2, strValue2
If strValue2 <> "" Then
'WScript.Echo "Install Date: " & strValue2
End If
objReg.GetDWORDValue HKLM, strKey & strSubkey, strEntry3, intValue3
objReg.GetDWORDValue HKLM, strKey & strSubkey, strEntry4, intValue4
If intValue3 <> "" Then
WScript.Echo "Version: " & intValue3 & "." & intValue4
End If
objReg.GetDWORDValue HKLM, strKey & strSubkey, strEntry5, intValue5
If intValue5 <> "" Then
'WScript.Echo "Estimated Size: " & Round(intValue5/1024, 3) & " megabytes"
End If
Next
Problem:
With current way the code is structured info.bat creates .csv file before the .txt files are created and values for Software_Needed (eg Adobe Flash | Hotfix for Windows) is available in %ComputerName%-programs-to-check.txt. Hence difficult to then update the .csv with the value for Software_Needed on the second row.
Proposed solution: (*)
I'm beginning to think the .vbs file should be called first to create %ComputerName%-programs.txt in the first .bat file, then in a second .bat file have the functionality in StripSoftware.bat to create %ComputerName%-programs-to-check.txt, and then use that and other information to create %ComputerName%.csv
Questions:
1) Would appreciate peoples thoughts, comments and views on the Proposed Solution
2) Suggestions as to better solutions than the proposed Solution.
It's unclear what you want. This is a standard post of mine. Then I'll show you something.
Start - All Programs - Accessories - Right click Command Prompt and choose Run As Administrator. Type (or copy and paste by right clicking in the Command Prompt window and choosing Paste). Type for table format
wmic /output:"%userprofile%\desktop\WindowsInstaller.html" product get /format:htable
or in a form format
wmic /output:"%userprofile%\desktop\WindowsInstaller.html" product get /format:hform
It will create a html file on the desktop.
Note
This is not a full list. This is only products installed with Windows Installer. There is no feature for everything.
However as I said in my previous post nearly everything is listed in the registry.
So to see it in a command prompt
reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /s
or in a file
reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /s>"%userprofile%\desktop\WindowsUninstall.txt"
To see it in notepad in a different format
Click Start - All Programs - Accessories - Right click Command Prompt and choose Run As Administrator. Type Regedit and navigate to
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
Right click the Uninstall key and choose Export. If you save as a reg file (there is also text file, they are slightly different text formats) you need to right click the file and choose Edit to view it.
To view Windows Updates
wmic /output:"%userprofile%\desktop\WindowsUpdate.html" qfe get /format:htable
Here is a VBS script that get installed programs, sorts, and filters.
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set rs = CreateObject("ADODB.Recordset")
Set wshshell = CreateObject("wscript.shell")
Set Outp = Wscript.Stdout
ComputerName=WshShell.ExpandEnvironmentStrings("%Computername%")
'Build database with Computername and Softwarename
With rs
.Fields.Append "ComputerName", 201, 5000
.Fields.Append "Txt", 201, 5000
.Open
'Get list installed programs
Set colItems = objWMIService.ExecQuery("Select * From Win32_Product")
'Add to database
For Each objItem in colItems
.AddNew
.Fields("ComputerName").value = ComputerName
.Fields("Txt").value = objItem.Name
.UpDate
Next
'Sort Database on software name
'Sort and filter it - Softwarename acending (Txt) and filter only those starting M
.Sort = "Txt ASC"
.Filter = "Txt like 'm*'"
'write out to a CSV
Do While not .EOF
Outp.writeline .Fields("ComputerName").Value & "," & .Fields("Txt").Value
.MoveNext
Loop
End With
To use
cscript //nologo <path to vbs file> > OUTPUTFILE
This is the output
SERENITY,Microsoft .NET Framework 1.1
SERENITY,Microsoft .NET Framework 3.5 SP1
SERENITY,Microsoft .NET Framework 4 Client Profile
SERENITY,Microsoft .NET Framework 4 Extended
SERENITY,Microsoft Application Compatibility Toolkit 5.0
SERENITY,Microsoft Application Error Reporting
SERENITY,Microsoft Calculator Plus
SERENITY,Microsoft Device Emulator version 3.0 - ENU
SERENITY,Microsoft Document Explorer 2005
SERENITY,Microsoft Filter Pack 1.0
SERENITY,Microsoft LifeCam
SERENITY,Microsoft Mathematics
SERENITY,Microsoft Network Monitor 3.0
SERENITY,Microsoft Office XP Professional
SERENITY,Microsoft OpenType Font File Properties Extension
SERENITY,Microsoft Search Enhancement Pack
So there are three places where you can discard items. In the WMI select.
Set colItems = objWMIService.ExecQuery("Select * from Win32_Product where Name='Microsoft LifeCam'")
And also in the filter as shown above using similar syntax.
Also while writing it back you can compare it then and not write the ones you don't want.

Re-map linked tables in Access 2010

I am a relative novice with Access and starting from scratch with coding, so be gentle.
I have an Access 2010 database with dozens of linked tables based on .txt files. Sometimes the database moves, the source files move or the file server just gets re-named. In these events I am looking for a simple way for a user of the database to remap and refresh the linked tables. Ideally, it would be user prompted, i.e. the user pushes a button to refresh from a navigation form or something. Then, the system prompts for the new folder location. The folder location would house all of the necessary files, so it only needs to be selected one time. Once selected, all linked tables should remap and refresh with the user getting an error or success message.
I have seen a lot of these questions asked, but they seem to be in older versions of Access or it is not asking for a user prompt or for a user to browse for the new path.
Thanks.
While I agree with Marc B that this seems like a very oddly constructed database you could use the following code the manually link the tables again to the proper location. You would need to work this into a system that can loop through all tables and do them all one by one or adjust this code to do that automatically. But you may want to just rethink your system.
Function SetTableLinkPath(strTableName As String, strTablePath As String)
If Nz(strTableName, "") <> "" And Nz(strTablePath, "") <> "" Then
Dim cdb As DAO.Database
Set cdb = CurrentDb
cdb.TableDefs(strTableName).Connect = ";DATABASE=" & strTablePath
cdb.TableDefs(strTableName).RefreshLink
MsgBox "Table link for " & strTableName & " has been successfully set to the path: " & strTablePath & "."
Else
MsgBox "You must enter a valid Table path and name!"
End If
End Function

A data diff tool for finding the difference between two Access MDB Files

I have two different MDB files [with the same structure]. Is there an existing tool that can report the difference between the two files [row by row]?
I found a program called "MDBDiff" on SF, however the program is no longer available for download.
I've made an AccdbMerge utility that is able to compare data and programming objects as well. In scope of "row by row" comparison - it will show what records were added/modified/removed, for modified records it will highlight fields with updated values.
See the following page and go down a bit for a list of utilities to compare Access databases
http://www.granite.ab.ca/access/thirdparty.htm One of those might be what you're looking for.
I wanted to do the same (basically use DIFF to see differences row by row) so
1) I exported all the tables:
Option Explicit
Option Compare Database
Private Sub ExportAllTables()
Dim myDatabase As Database
Dim myTableDef As TableDef
Dim strTableName As String
Set myDatabase = CurrentDb
For Each myTableDef In myDatabase.TableDefs
DoEvents
strTableName = myTableDef.Name
DoCmd.TransferText _
acExportDelim, _
, _
strTableName, _
Environ("USERPROFILE") & "\DeskTop\dump\" & strTableName & ".CSV", _
True
Next myTableDef
MsgBox "Done"
End Sub
2) concatenated them into one file
type *.csv > all.txt
CAT will do as well if you have it
3) diff'ed them
diff all.txt all2.txt
Try using SQL Data Compare from Redgate, http://www.red-gate.com/products/SQL_Data_Compare/index.htm
and then use this trick,
http://www.red-gate.com/messageboard/viewtopic.php?p=15296#15296
I haven't tried it yet but this tool looks like it would do the job http://www.datanamic.com/download/download-datadiff-for-msaccess.html

MS Access 2003 - Sparkline Graphs in Microsoft Access

Hey guys. Just wondering if anyone knows of a method to create sparkline graphs on a form in MS Access. The chart builder does not really work very well to create sparkline charts (graphs that small).
Just curious, thanks!
I don't think there is anything built in for Sparkline graphs in MS Access. You have to use a third party control and deploy it along with your app to all users or use MS Excel embedded control to show the graph.
There is a VBA-powered sparkline solution featured on the Access blog fairly recently: http://blogs.office.com/b/microsoft-access/archive/2011/02/10/power-tip-add-sparkline-like-graphs-to-access-reports.aspx
They have an .mdb as well as an .accdb sample file available, so I'm guessing it works across multiple versions.
I started with the VBA-powered sparkline but didn't like that it looked low-resolution and I couldn't use it on a continuous form (it only works on reports). The solution I came up with was to build the charts in Excel and save the chart images in a subfolder. Then it's easy to link the image on a report or continuous form. My charts update nightly, though the Excel chart building loop is really fast. The slow part is generating the data that the charts need, which may vary depending on what you are charting.
I created a template in Excel that had a chart with the look and resolution that I wanted. I wrote a VBA routine in Access to open an Excel sheet and loop through each record that I wanted to chart. The sheet is passed to this function (below), which loads a records of chart data and passes it into Excel, which automatically refreshes the 'SparkChart' object. It then saves the image to a subfolder. The Excel sheet stays open and is re-used with each loop. I didn't include the function with the loop.
Here's what my chart looks like in Excel:
Here is an example of the Sparklines shown in a continuous form:
Public Function fCreateSparklineChart(pDQ_ID As Long, pChartSheet As Object) As Boolean
' Pass in a Dashboard Query ID for data that has already compiled into the top-n
' temp table and the data will be copied to the passed pChartSheet in Excel. This
' will update a chart object, then the chart is saved as a .png file.
Dim strSQL As String
Dim strChartPath As String
Dim rs As DAO.Recordset
On Error GoTo ErrorHandler
' Get chart data from a table that has already been compiled with
' min and max values as percentages so the lowest value is 0
' and the highest value is 100.
strSQL = " SELECT DQ_ID, Trend_Value, " & _
" IIf(Trend_Value=0,0,Null) AS Min_Point, " & _
" IIf(Trend_Value=100,100,Null) AS Max_Point " & _
" FROM " & DASHBOARD_TMP_TABLE & _
" WHERE (DQ_ID=" & pDQ_ID & ") "
strSQL = strSQL & " ORDER BY RowNo "
Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
If rs.RecordCount > 0 Then
pChartSheet.Range("A1").CurrentRegion.Clear
pChartSheet.Range("A1").CopyFromRecordset rs
pChartSheet.ChartObjects("SparkChart").Chart.SetSourceData pChartSheet.Range("rngData")
' Use a filename that includes the record ID.
strChartPath = CurrentProject.Path & "\Images\Sparkline_DQ_ID_" & Format(pDQ_ID, "0000") & ".png"
' Delete the file if it already exists.
DeleteFile strChartPath
' Save the Excel chart as a png file.
pChartSheet.ChartObjects("SparkChart").Chart.Export strChartPath, "png"
fCreateSparklineChart = True
End If
Exit_Function:
Exit Function
ErrorHandler:
fCreateSparklineChart = False
MsgBox "Error #" & err.Number & " - " & err.Description & vbCrLf & "in procedure fCreateSparklineChart of basSparkline"
GoTo Exit_Function
End Function
I've been thinking of creating a YouTube video explaining how I built this Data Quality Dashboard to chart data trends. Let me know if you are interested and I may be encouraged to do it.